Hi Andy,
Adding a DropDownlist in the ItemTemplate (instead of the EditItemTemplate)
means that you have to add the event handler for the SelectedIndexChanged in
one of the following datagrid item events (e.g. OnItemCreated
OnItemDataBound). Which in turn means that upon postback you have to re-bind
the datagrid during the initialization of the page, as in those 2 examples:
http://www.societopia.net/Samples/DataGrid_6c.aspx http://www.societopia.net/Samples/Da...Delegates.aspx
This however will prove challenging in 3 scencarios:
1- If you want to edit the grid by adding a EditCommandColumn because you
will lose the ViewState of the textboxes within the EditItemTemplate.
2- If data in the dropdownlists are repeated then you might consider a
client side approach by replacing the dropdownlist by a Textbox as in this
example
http://www.societopia.net/samples/textbox.htm
3- Because the dropdownlist is displayed on each row (instead of only upon
edit), the page size might be large (imagine the size of the ViewState if you
display 100 records in each dropdownlist in a datagrid that has 20 rows)
--
HTH,
Phillip Williams
http://www.societopia.net http://www.webswapp.com
"Andy" wrote:
Hello,
I have a datagrid which contains DropDownList as follow:
<Columns>
<asp:TemplateColumn >
<ItemTemplate>
<asp:DropDownList id=ProductName
onSelectedIndexChanged=ProductName_IndexChange>... .
Now, in the method ProductName_IndexChange I want to write codes to
handle when user select the dropdown list. Assume there are 10 rows in
my datagrid, how do I know which row the user select from? Is there a
property in datagrid that gives me the item index when an event
happens?
Thanks so much.