GridView在当前上下文中不存在(updatepanel)

时间:2017-03-08 11:54:04

标签: asp.net ajax gridview webforms updatepanel

我尝试将GridView与SqlDataSource和Button放在UpdatePanel中,但是我遇到了一些错误。我怎么能这样做?

Image

2 个答案:

答案 0 :(得分:0)

我忘了ContentTemplate。现在它的作品:))

答案 1 :(得分:0)

 <div align="center" class="container-fluid">
    <div class="row">
    <asp:GridView ID="GridView1" runat="server" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="2" CellSpacing="4" CssClass="table table-bordered table-hover" Font-Names="Arial" >

        <Columns>
            <asp:TemplateField HeaderText="User Actions">
                <ItemTemplate>
                    <asp:HyperLink ID="Button3" runat="server" class="btn btn-success btn-md" NavigateUrl='<%# Eval("id","Update.aspx?id={0}") %>' OnClick="Button3_Click1" Text="Update" />
                    <asp:HyperLink ID="Button4" runat="server" class="btn btn-danger btn-md" NavigateUrl='<%# Eval("id","Delete.aspx?id={0}") %>' OnClick="Button2_Click" Text="Delete" />
                    <asp:HyperLink ID="HyperLink1" runat="server" class="btn btn-info btn-md" NavigateUrl='<%# Eval("id","View.aspx?id={0}") %>' OnClick="Button4_Click" Text="Read" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Select">
                <ItemTemplate>
                    <asp:CheckBox ID="checkbox1" runat="server" Checked="false" Enabled="true"/>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>

这是一种在asp.net中添加网格视图的方法,在后端代码中你必须用C#代码编写这个代码

GridView1.DataSource = dt;
        GridView1.DataBind();