views:

1729

answers:

4

hi all

i want to add a datasource to dropdownlist this dropdownlist is one of the column of gridview here i want to add a datasource to dropdownlist at dynamically without using the sqldatasource

(vs2008 and c#)

+1  A: 

You could implement the OnDataBinding event for the dropdownlist control in your grid. In the event you could assign the DataSource property and other attributes to whatever you like. Bind it to a List<YourObject> even.

Doing it on the OnDataBinding event also allows you to customize the values in the ddl on the fly as well. So each row's ddl could have a different set of options available based on some other data in your row if you need that type of functionality.

Tons of flexability with the ASP.NET controls if the OnDataBinding method is used instead of the auto (easy mode) wire ups.

Kelsey
thnx for ur quick reply yes it will work
thiru
pls tell me i set datasource like OnDataBinding event DropDownList11.DataSource = dataTable; DropDownList11.DataValueField = "ProjectCode"; DropDownList11.DataTextField = "ProjectCode"; DropDownList11.DataBind();but the error will occur like the name "DropDownList11" does not exist in the current context
thiru
A: 

I do agree with kelsey... you should use onDataBinding event.

Meetu Choudhary
thnx for ur quick reply yes it will work
thiru
pls tell me i set datasource like OnDataBinding event DropDownList11.DataSource = dataTable; DropDownList11.DataValueField = "ProjectCode"; DropDownList11.DataTextField = "ProjectCode"; DropDownList11.DataBind(); but the error will occur like the name "DropDownList11" does not exist in the current context
thiru
yes as it is in the itemtemplate so you ont get it directly for that you have to use findcontrol.
Meetu Choudhary
A: 

Refer link below

Populating dropdownlist in gridviw

.

+1  A: 

yes as it is in the itemtemplate so you wont get it directly for that you have to use findcontrol

Meetu Choudhary