Really simple, but im missing something?! Binding to a label from a datasource in .net2 c#
-
Ive been using .net2 for a short while and have mastered the basics of using FormViews, DetailsViews and the like but I cant seem to see how to go about binding fields from a datasource to Labels?! Can anyone please help, its driving me crazy?:doh::sigh: Thanks Adam
-
Ive been using .net2 for a short while and have mastered the basics of using FormViews, DetailsViews and the like but I cant seem to see how to go about binding fields from a datasource to Labels?! Can anyone please help, its driving me crazy?:doh::sigh: Thanks Adam
-
Thanks for the reply. I dont know, how would i go about adding this? my heads in a right muddle! Id need to reference the datasource somewhere first though wouldnt i? How do I do this? Adam
No Problem!!! Lets say that you have a gridview1 and the datasource given to the gridview1 is ds!! Assume that the resultant ds has a table with 5 rows and 3 columns col a, col b, col c. No in your grid under the itemtemplate you would have added the label right! there you would just include the binding logic ex: DataBinder.Eval(Container.DataItem,"col a") ....... ....... ...... ......
Gautham
-
Ive been using .net2 for a short while and have mastered the basics of using FormViews, DetailsViews and the like but I cant seem to see how to go about binding fields from a datasource to Labels?! Can anyone please help, its driving me crazy?:doh::sigh: Thanks Adam
Hi There are lots of examples for form view using SQL Data Source. Here is an example to bind data in labels using VS.Net 2005 (C#.net 2.0) Simply drag and drop SQL Data source in your application. Right click the Data source, click Configure Data Source. If this is the first time you are connecting to Database then Click New connection, Type Server Name, User Name & Password. Select database from the list after entering valid user name and password. Connection String will be populated automatically in the list. Click next, select table from the list. You can modify your query later using the SELECT property of SQLDataSource. If you don’t want SQLDatasource, you can add a connection string in Web.config and use the same. No need to worry about that now. You need to explore more on this. For beginners, use SQL Data source. Try without DataSource later as most applications use Stored Procedures. Now add Form or Details or Grid view in your application; go to DataSourceID property of the control (formview or detailsview or gridview). Select DataSourceID from the list as you have added in your application. By default all fields will be bind automatically. Just take a note: .net uses the following expression for binding text:
- <%# DataBinder.Eval(Container.DataItem,”columnname”%> - for gridview
- <%# Bind(“Columnname”) %> - for formview or detailsview
- <%# Eval(“Columnname”) %> - for formview or detailsview
Try other controls like GridView. All the best
Rate this message. Thank you. Harini :)
-
No Problem!!! Lets say that you have a gridview1 and the datasource given to the gridview1 is ds!! Assume that the resultant ds has a table with 5 rows and 3 columns col a, col b, col c. No in your grid under the itemtemplate you would have added the label right! there you would just include the binding logic ex: DataBinder.Eval(Container.DataItem,"col a") ....... ....... ...... ......
Gautham
Its not linked with a gridview or anything as an item template, that part i can do. Basically what i want is that there is a list of records in a listbox. You then can select a record which will then close the listbox and populate some labels with the persons email, name etc. This is so that I can easily pull these records as I will want to add these into the database as it is part of a wizard form i am building for people to fill in. Hope this makes sense. Thanks Adam
-
Hi There are lots of examples for form view using SQL Data Source. Here is an example to bind data in labels using VS.Net 2005 (C#.net 2.0) Simply drag and drop SQL Data source in your application. Right click the Data source, click Configure Data Source. If this is the first time you are connecting to Database then Click New connection, Type Server Name, User Name & Password. Select database from the list after entering valid user name and password. Connection String will be populated automatically in the list. Click next, select table from the list. You can modify your query later using the SELECT property of SQLDataSource. If you don’t want SQLDatasource, you can add a connection string in Web.config and use the same. No need to worry about that now. You need to explore more on this. For beginners, use SQL Data source. Try without DataSource later as most applications use Stored Procedures. Now add Form or Details or Grid view in your application; go to DataSourceID property of the control (formview or detailsview or gridview). Select DataSourceID from the list as you have added in your application. By default all fields will be bind automatically. Just take a note: .net uses the following expression for binding text:
- <%# DataBinder.Eval(Container.DataItem,”columnname”%> - for gridview
- <%# Bind(“Columnname”) %> - for formview or detailsview
- <%# Eval(“Columnname”) %> - for formview or detailsview
Try other controls like GridView. All the best
Rate this message. Thank you. Harini :)
-
Ive been using .net2 for a short while and have mastered the basics of using FormViews, DetailsViews and the like but I cant seem to see how to go about binding fields from a datasource to Labels?! Can anyone please help, its driving me crazy?:doh::sigh: Thanks Adam
Very simple e.g.,
myLabel.text = dataTable.Rows(0).Items(0)
It depends on what your datasource is... -
Very simple e.g.,
myLabel.text = dataTable.Rows(0).Items(0)
It depends on what your datasource is...