dropdownlist in datagrid



Hey guys,
I am new here, so i hope this works out:

I have a datagrid which I populate with data from XML file. In
EditItemTemplate I have a dropdownlist. How do I fire
myDataGrid_UpdateCommand upon SelectedIndexChanged event in the
dropdownlist? thank you.

<ASP:DataGrid id="myDataGrid" runat="server"
AutoGenerateColumns="False" HeaderStyle-BackColor="#aaaadd"
Font-Size="8pt" ShowFooter="True" BorderColor="Black"
BackColor="WhiteSmoke" AllowSorting="true">
<HeaderStyle BackColor="LightGray"></HeaderStyle>
<FooterStyle BackColor="LightGray"></FooterStyle>
<ASP:TemplateColumn HeaderText="Date"


<ASP:TemplateColumn HeaderText="Subject"
<%#DataBinder.Eval(Container.DataItem, "subject")%>
<asp:TextBox ID="subjectTxt" style="size:15" Text=' <%#
DataBinder.Eval(Container.DataItem, "subject") %> ' runat="server"
Width="100" />


<ASP:TemplateColumn HeaderText="First Name"
<%#DataBinder.Eval(Container.DataItem, "first_name")%>
<asp:TextBox ID="firstTxt" style="size:15" Text=' <%#
DataBinder.Eval(Container.DataItem, "first_name") %> ' runat="server"
Width="100" />


<ASP:TemplateColumn HeaderText="Message"
<%#DataBinder.Eval(Container.DataItem, "description")%>

<asp:TextBox ID="descTxt" runat="server" Height="100px"
TextMode="MultiLine" Width="333px" Text='<%#
DataBinder.Eval(Container.DataItem, "description") %> '/>

<ASP:TemplateColumn HeaderText="Status"
<%#DataBinder.Eval(Container.DataItem, "approved")%>
<asp:DropDownList ID="lstSubject" runat="server"
Width="110px" AutoPostBack="True">
<asp:ListItem Value="Delete">Delete/Enter a

<asp:EditCommandColumn CancelText="Cancel" EditText="Edit"
HeaderText="Edit" UpdateText="Update">

<asp:ButtonColumn CommandName="Delete" HeaderText="Delete"



Christopher Reed

First of all, since you're editing the entire record, you really don't want
to call the UpdateCommand in the middle of editing your record values. By
not using the AutoPostBack on the dropdownlist, your users will be given
another opportunity to check their entries.

Secondly, there is no reason to call SelectedIndexChanged unless you have
another process you need to run besides updating your data. Regardless of
whether you have this event or not, the UpdateCommand event should fire once
you check the Update button on the record, and since your dropdownlist
selection should be retained, it will update along with all of the other
values. Additionally, you can also have a SelectedIndexChanged method that
will also fire at some point in the process (you'd need to look at the
event-handling process in general to see what the event order would be).

You really want to use the SelectedIndexChanged, you can always build your
own SqlCommand and use an ExecuteNonQuery method to perform your update, but
I wouldn't recommend this.

Hope this helps!

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question