Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

gridview databinding from codebehind

0 views
Skip to first unread message

chacal

unread,
Aug 5, 2008, 9:18:23 AM8/5/08
to
hi,

I wanted to populate a gridview from codebehind. The data comes from
10 different tables.
The table from which data is to be taken is chosen using a
dropdownlist.

I needed to update some of the fields shown on the gridview.

The no. of fields will be different for different tables.

Also, one of the fields in 6 of these tables must display a dropdown
list, for editing.

Can somebody help me..?

Steve

unread,
Sep 3, 2008, 11:22:19 PM9/3/08
to
All of this is doable.

You can dynamically update the Select command of your SQLDataSource
depending on which drop-down value you select.
The GridView should be set to auto-generate the columns.

Example:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs
e)

{

SqlDataSource1.SelectCommand = DropDownList1.SelectedValue;

}

For this example, I put the SQL string in the value of the DropDownList
item. For security reasons, you probably want to assign a string
programmatically using a switch structure to avoid SQL injection attacks.

I think that you will have to add in the DropDownField afterwards through
code, but am not quite sure how to go about this. Perhaps someone else will
jump in here with a clever suggestion.

HTH

Steve

"chacal" <rohin...@gmail.com> wrote in message
news:3fe0a017-8964-41e6...@i24g2000prf.googlegroups.com...

0 new messages