本文介绍了更改下拉列表选择时的GridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我有一个gridview.gridview中的一列具有所有行的下拉列表.更改任何gridview下拉框选择时是否可以触发方法?
So I have a gridview. One of the columns in the gridview has a drop down list for all rows. Is it possible to fire a method when any of the gridview drop down boxes selection is changed?
我尝试在项目模板中为下拉列表添加onselectedindexchange,但它不起作用.
I tried adding the onselectedindexchange for the drop down list in the item template but it did not work.
有什么想法吗?
<Gridview>
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList runat="server">
<asp:ListItem Value="Yes">Yes</asp:ListItem>
<asp:ListItem Value="No">No</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</GridView>
推荐答案
您可以使用更改的选定索引来假设这是网格内部的下拉列表
You can use selected index changed to suppose this is the dropdown inside your grid
<Gridview>
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</GridView>
您可以具有以下功能
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddl = (DropDownList)sender;
GridViewRow row = (GridViewRow)ddl.Parent.Parent;
int idx = row.RowIndex;
// TextBox txtECustCode = (TextBox)row.Cells[0].FindControl("txtECustCode");
这篇关于更改下拉列表选择时的GridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!