0

我在我EditItemTemplateGridView1.

<EditItemTemplate>
    <asp:Label ID="Label1" runat="server" Text="<%# bind('ftype') %>"></asp:Label>
    <asp:Label ID="Label2" runat="server" Text="<%# bind('ftname') %>"></asp:Label>
    <asp:Label ID="Label3" runat="server" Text="<%# bind('fsname') %>"></asp:Label></br>
    <asp:Label ID="Label4" runat="server" Text="<%# bind('fa1') %>"></asp:Label></br>
    <asp:Label ID="Label5" runat="server" Text="<%# bind('fa2') %>"></asp:Label></br>
    <asp:Label ID="Label6" runat="server" Text="<%# bind('fa3') %>"></asp:Label></br>
    <asp:TextBox ID="TextBox1" Width="30px" runat="server"></asp:TextBox>
    <asp:TextBox ID="TextBox2" Width="30px" runat="server"></asp:TextBox>
    <asp:TextBox ID="TextBox3" Width="30px" runat="server"></asp:TextBox>
    <asp:TextBox ID="TextBox4" Width="30px" runat="server"></asp:TextBox>
 </EditItemTemplate>

现在在我的GridView1_RowEditing函数中,我想访问Label4文本。我使用FindControl但只找到控件并没有返回文本。

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
    Label Label1 = (Label)GridView1.FindControl("Label4");
    if (Label1.Text == null)
    {
        //some code
    }
}L

如何访问 中text的任何label存在Gridview

4

1 回答 1

0

用这个,

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
    Label label = (Label)this.GridView1.Rows[e.NewEditIndex].FindControl("Label4");
    string value = label.Text;
}
于 2013-09-07T09:33:56.250 回答