PC Review


Reply
Thread Tools Rate Thread

Bind data to TextBox

 
 
G
Guest
Posts: n/a
 
      5th Feb 2007
Hello,

Fairly new to .net (using c#).

I am running an SQL query which always returns ONE ROW and no more. I would
like to have the ID field of the returned row bound to a TextBox onSubmit.

AT the moment I have used the following controls:

<asp:SqlDataSource ID="DStypes" runat="server" />
<asp:GridView ID="GVtypes" runat="server"
DataSourceID="DStypes">
</asp:GridView>

This returns the entire row, I was using this to test the data returned was
correct. I would like to amend this code if possible to no longer return
the datagrid, but simply the value of the ID field, and stick it inside my
TextBox.

Should I be using SqlDataSource to achieve this?

Regards,

Gary.

 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      5th Feb 2007
Gary,

Make a SqlCommand object for the query that will return only one field, then
call its ExecuteScalar method. This will return the ID value. Once you have
the value, you can convert it to string with the ToString method and assign
to your textbox's Text property.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


"G" <(E-Mail Removed)> wrote in message
news:7591CBBE-BEDF-4E53-99AF-(E-Mail Removed)...
> Hello,
>
> Fairly new to .net (using c#).
>
> I am running an SQL query which always returns ONE ROW and no more. I
> would like to have the ID field of the returned row bound to a TextBox
> onSubmit.
>
> AT the moment I have used the following controls:
>
> <asp:SqlDataSource ID="DStypes" runat="server" />
> <asp:GridView ID="GVtypes" runat="server"
> DataSourceID="DStypes">
> </asp:GridView>
>
> This returns the entire row, I was using this to test the data returned
> was correct. I would like to amend this code if possible to no longer
> return the datagrid, but simply the value of the ID field, and stick it
> inside my TextBox.
>
> Should I be using SqlDataSource to achieve this?
>
> Regards,
>
> Gary.



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bind a textbox to Access data Geo R Microsoft Excel Misc 0 16th Jan 2008 04:45 PM
Bind a hyperlink to a textbox or field data? Help!!! me thanks alot Microsoft Access 0 5th Jan 2007 05:27 PM
Data Bind for textbox =?Utf-8?B?ZGF2aWQ=?= Microsoft ASP .NET 3 4th Apr 2005 12:55 AM
how to bind data to textbox from dataset? Rich Microsoft VB .NET 7 27th Jan 2004 07:15 AM
Can we bind data to textbox in a headertemplate of a datagrid Vijaya Microsoft ASP .NET 2 13th Nov 2003 06:42 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:48 AM.