GridView控件

时间:2009-12-25 09:33:04

标签: asp.net gridview

我有一个网格控件。我想从其他控件访问gridview子控件。

例如:

<asp:UpdatePanel ID="upPersonelAssignment" runat="server">
<ContentTemplate>
        <asp:Label ID="lblPersonelName" runat="server" ></asp:Label>
        <asp:Label ID="lblUpdatedDateTime" runat="server" ></asp:Label>
        <div id="divPersonelAssignmentSearch">
            <asp:GridView ID="gvPersonelAssignment" runat="server" DataSourceID="odsPersonelBLL" 
                AllowSorting="True" AutoGenerateColumns="False" 
                onrowdatabound="GridView1_RowDataBound">
                <Columns>
                    <asp:CommandField CancelText="Vazgeç" EditText="Amir Ata" ShowEditButton="True" 
                        UpdateText="Amir Kaydet" />
                    <asp:TemplateField HeaderText="Sicil No">
                        <ItemTemplate>
                            <asp:Label ID="lblPersonelSicilNo" runat="server"  Text='<%# Eval("personelSicil") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="İsim">
                        <ItemTemplate>
                            <asp:Label ID="lblPesonelFirstName" runat="server" Text='<%# Eval("personelAdi") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField> ...
...........
                    <asp:TemplateField HeaderText="Amir Liste">
                        <ItemTemplate>
                            <asp:Label ID="lblAmirList" runat="server" Text="Amir Liste"></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
...........

        <div id="divDropDownExtender" runat="server">
            <act:DropDownExtender ID="ddeAmirList" runat="server" 

            TargetControlID="lblAmirList" DropDownControlID="">

            </act:DropDownExtender>
        </div>

但我有错误:'ddeAmirList'的TargetControlID无效。无法找到ID为“lblAmirList”的控件

如何从其他控件访问网格视图子控件?

2 个答案:

答案 0 :(得分:0)

您必须在GridView控件中放置扩展器才能在控件的模板中工作。

答案 1 :(得分:0)

使用ondatabound甚至gridview

您可以通过编写以下内容来访问gridview中的控件:

protected void YourGridView_DataBound(object sender, EventArgs e)
{
    Label label1 = (Label)e.Row.Cells[0].FindControl("lblAmirList");
    // access your control
    label1.Text = "sdfs";

    // do this for other controls inside gridview

}