【问题标题】:reading values from gridview template field in asp.net从 asp.net 中的 gridview 模板字段读取值
【发布时间】:2015-04-12 16:54:38
【问题描述】:

这是 gridview 中模板字段的代码。我想使用 c# 代码在字符串中获取此字段的值。

<asp:TemplateField HeaderText="Status" SortExpression="Status">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Status") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:DropDownList ID="DropDownList2" runat="server">
                                    <asp:ListItem Value="P"></asp:ListItem>
                                    <asp:ListItem Value="L"></asp:ListItem>
                                    <asp:ListItem Value="A"></asp:ListItem>
                                </asp:DropDownList>
                            </ItemTemplate>
                        </asp:TemplateField>

我尝试了以下代码,但它不起作用。 这是我读取值的代码。

 string str = gridview1.Rows[0].Cells[0].Text.ToString();

但它返回空字符串。如何获得选定的值。

【问题讨论】:

    标签: c# asp.net aspxgridview


    【解决方案1】:

    您找不到这样的下拉选择值。您需要先使用FindControl方法找到控件:-

    DropDownList DropDownList2 =  (DropDownList)gridview1.Rows[0].Cells[0]
                                                         .FindControl("DropDownList2");
    string str = DropDownList2.SelectedValue;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-08
      • 1970-01-01
      • 2012-02-22
      • 2014-07-07
      相关资源
      最近更新 更多