【问题标题】:How to get selected value of dropdownlist in edititemtemplate - datagridview?如何在edititemtemplate-datagridview中获取下拉列表的选定值?
【发布时间】:2013-04-15 10:25:07
【问题描述】:

我在 DataGrid EditItemTemplate 中创建了一个 DropDownList。 (手动)

<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" 
                        DataSourceID="SqlDataSource1" DataTextField="nazwa" DataValueField="nazwa" 
                        SelectedValue='<%# Bind("nazwa") %>'>
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:baza_pismConnectionString1 %>" 
                        SelectCommand="SELECT [nazwa] FROM [podmioty]"></asp:SqlDataSource>
</EditItemTemplate>

如何从后面代码中的下拉列表中获取选定的值?

【问题讨论】:

  • 当你想要下拉选择的值时,我的意思是在哪个事件
  • 尝试查看 DropDownList 的 CommandName 和 CommandArgument 属性,以及 GridView 的 OnRowCommand 属性/事件。

标签: c# asp.net gridview drop-down-menu


【解决方案1】:

我猜你想在编辑时找到下拉菜单的值,这段代码就可以了

    protected void gridview1_RowEditing(object sender, GridViewEditEventArgs e)
        {
GridViewRow row = gridview1.Rows[e.RowIndex];

            DropDownList ddl = row.FindControl("DropDownList1") as DropDownList;
        var value=ddl.SelectedValue;
            //now do whatever with that value
        }

【讨论】:

  • 我有错误。当前上下文中不存在名称“行”。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-28
  • 2020-12-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多