Click here to Skip to main content
15,899,313 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi every body,

I want to bind textBox1 or Label with SQL Server in ASP.net application with C#.
I want to write code like this:

MIDL
textBox1.DataBindings.Add("Text", ds.Tables["Products"], "ProductName");


But this property not appear for me: (DataBindings )
appear that only: (DataBind) , (DataBinding) so (Add method) not appear accordingly.

Any one can tell me why this property not appear for me (DataBindings )

please help me
Thanks.
Posted
Comments
Sunasara Imdadhusen 15-Oct-10 2:57am    
Why you are binding text instead of assign value to Text?
MrLonely_2 15-Oct-10 10:05am    
Sorry,
I want to bind Label.text & Hyperlink.text with database not Textbox
Please help me..........
MrLonely_2 15-Oct-10 14:46pm    
Any body help me please............

Have a read of Two-Way Data Binding in ASP.NET[^]

** UPDATE **
You are trying to use WinForm data binding with a WebForm this does not work.
If you read the article you should have read the section entitled "Simple DataBinding - a (brief) refresher" and seen the DataBinder.Eval() Method[^] which is what is used to databind controls in WebForms.

To use the DataBinder.Eval() method in CodeBehind;
TextBox1.Text = DataBinder.Eval(ds.Tables["Products"].DefaultView[0], "ProductName").ToString();

This method also has the option to specify a format string;
TextBox2.Text = DataBinder.Eval(ds.Tables["Products"].DefaultView[0], "ProductPrice", "{0:c}"); //Display using currency format


If however all you want is to do is change the text of a label based on a database field you could just use string.Format() like;
Label1.Text = string.Format("{0}", ds.Tables["Products"].DefaultView[0]["Description"]);


Keep in mind that WebForm databinding does not work the same way as WinForm databinding and attempt to comprehend how things work.
 
Share this answer
 
v2
Comments
MrLonely_2 15-Oct-10 10:07am    
I do not understand right from this article
Please i want clear and definite code to use it.
MrLonely_2 15-Oct-10 14:46pm    
Any body help me please............
textbox1.text='<%#Eval("columnname")%>'

Same for label or linkbutton text
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900