Hi,
I use a filter on a sqlDataSource which has uniq rows. I need to bind several fields of the result filtered row to textboxes. Here the code :
SqlDataSource dsPrev = (SqlDataSource)PreviousPage.FindControl("SqlDataSource1");
dsPrev.FilterExpression = "dr_id='" + id + "' ";
GridView gvTemp = new GridView();
gvTemp.DataSource = dsPrev;
gvTemp.DataBind();
TextBox1.Text = gvTemp.Rows[0].Cells[3].Text;
Is there a more professional way to do it ?
Thanks,
David
Anwar BuchooPosted Jun 30, 2006, 4:29 AM
In the ItemTemplate of the dataList object, at as many textboxes as you have fields.
Then, set the TextBox.Text value to DataBind.Eval(Container.DataItem, "corresponding fieldname") in the code in-front like follows:
Text='<%# DataBinder.Eval(Container.DataItem,"fieldname") %>'
Cheers
DavidPosted Jun 15, 2006, 3:22 AM
You stopped just where I have the problem. How can I bind this textbox to a field in the dataview ?
Thanks for your help.
David
Tirthadip MukhopadhyayPosted Jun 15, 2006, 2:55 AM
use dataview.Instantiate a dataview from the dataset table.dataview has a method called filter,i suppose you know.place your filter condition like---
mydataview.Filter="filter condition";
now bind your textboxes by that filtered values.
hope this will do.
happy programming.
Tirthadip.