dropdownlist in datagrid


S

sergeyr3

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.
-Sergey

<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>
<Columns>
<ASP:TemplateColumn HeaderText="Date"
SortExpression="announcement_date">
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem,
"announcement_date")%>
</ItemTemplate>

</ASP:TemplateColumn>

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

</EditItemTemplate>
</ASP:TemplateColumn>

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

</EditItemTemplate>
</ASP:TemplateColumn>


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

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


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


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

<asp:ButtonColumn CommandName="Delete" HeaderText="Delete"
Text="Delete"></asp:ButtonColumn>
</Columns>
 
Ad

Advertisements

C

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

Top