【发布时间】:2011-05-26 18:51:45
【问题描述】:
我在 GridView 中的 TemplateField 中有一个下拉列表。
我想动态添加列表项并编写代码以在索引更改时进行处理。我该如何操作列表,因为当 DropDownList 在 TemplateField 中时我无法直接引用它。
这是我的代码:
<asp:TemplateField HeaderText="Transfer Location" Visible="false">
<EditItemTemplate>
<asp:DropDownList ID="ddlTransferLocation" runat="server" ></asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
【问题讨论】:
-
为什么不能直接引用DropDown? myGrid.Rows[index].FindControl("ddlTransferLocation") 作为 DropDownList。如果您使用它,可以从 GridView.SelectedIndex 找到索引。此外,一些每行 GridView EventArgs 暴露了触发事件的行(e.RowIndex,其中 e 是 GridView*EventArgs)
-
另外,您想“编写代码以在索引更改时进行处理”。你指的是哪个索引,GridView 还是每个 DropDownList?
标签: c# asp.net gridview drop-down-menu templatefield