【问题标题】:Asp.net GridView Get DropDownList value from itemlist on edit rowAsp.net GridView 从编辑行的项目列表中获取 DropDownList 值
【发布时间】:2020-07-18 15:33:42
【问题描述】:

我试图从使用项目列表的 DropdownList 控件中更新一个单元格,但是当我选择值并单击更新时,更新后的单元格是空的:

<asp:TemplateField HeaderText="Done BY">
    <ItemTemplate>
        <asp:Label ID="lblUser" width="100px" runat="server" Text='<%#Eval("User")%>'></asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
        <asp:DropDownList ID="DropDownListUser" runat="server" AppendDataBoundItems="true">
            <asp:ListItem Value="Alex" Text="Alex"></asp:ListItem>
            <asp:ListItem Value="Yan" Text="Yan"></asp:ListItem>
            <asp:ListItem Value="Yagi" Text="Yagi"></asp:ListItem>
        </asp:DropDownList>
    </EditItemTemplate>
</asp:TemplateField>

【问题讨论】:

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


    【解决方案1】:

    您必须将OnSelectedIndexChanged="DropDownListUser_SelectedIndexChanged" 添加到您的代码中,并在服务器端编写以下代码。这将使您可以动态更改名称并将其张贴在标签上;

    protected void DropDownListUser_SelectedIndexChanged(object sender, EventArgs e)
    {
        lblUser.Text = DropDownListUser.SelectedValue.ToString();    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-12
      • 1970-01-01
      • 2010-09-16
      • 1970-01-01
      • 2016-07-20
      • 2013-12-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多