Or Betzalel Or Betzalel - 6 months ago 31
ASP.NET (C#) Question

Drop Down List In A Gridview

I have a

, inside the
I have a template field and inside that, a drop down list.

<asp:DropDownList ID="Hello" runat="server">

I want to databind the
but how do I make the drop down list change its value to according to the information I gave it while databinding?

Im used to using DataField in bound fields

<asp:BoundField HeaderText="Hello" DataField="HelloDB" />


All you have to do is tap into the OnRowDataBind event of the GridView. Within that, you can use FindControl() to get the drop down, cast it as a DropDown, then set the value.

This event is called when each row is databound, so each dropdown would be updated.