错误:panel1在正确的上下文中不存在

时间:2009-07-21 13:39:21

标签: c# asp.net

如何解决此错误。

我的代码是

<asp:GridView ID="gridView" runat="server" Style="position: relative; left: 299px; top: 69px;" PageSize="5" OnRowCommand="gridView_OnRowCommand" AllowPaging="True" OnSelectedIndexChanged="gridView_SelectedIndexChan ged1" >

<PagerTemplate>
<% if (gridView.PageIndex > 0) 
{ %>
<asp:ImageButton ID="imgBtnPrevious" runat="server" Style="vertical-align: middle;" ImageUrl="pre.jpg" OnClick="click1" 
CommandArgument="Prev" CommandName="Page" /> 

<% } %> 

<%=(gridView.PageIndex * 5) + 1%> <%=(gridView.PageIndex * 5) + gridView.Rows.Count%> 
<% if (gridView.PageIndex != (gridView.PageCount - 1)) 
{ %> 



<asp:ImageButton ID="imgBtnNext" runat="server" Style="vertical-align: middle;" ImageUrl="next.jpg" OnClick="click" CommandArgument="Next" CommandName="Page" /> 
<% } %> 

<%--<asp:ImageButton ID="imgBtnNext" runat="server"
Style="vertical-align: middle;" ImageUrl="next.jpg" 
CommandArgument='<%# Eval("Next")%>' OnClick="click" CommandName="Page" />--%>
</PagerTemplate>
</asp:GridView>
</aspanel>
<%--<%=(gridView.PageIndex * 5) + 1%> <%=(gridView.PageIndex * 5) + gridView.Rows.Count%> --%> 
<% if (gridView.PageIndex != (gridView.PageCount - 1)) 
{ %> 



<asp:ImageButton ID="imgBtnNext" runat="server" Style="vertical-align: middle;" ImageUrl="next.jpg" OnClick="click" CommandArgument="Next" CommandName="Page" /> 
<% } %> 

<%--<asp:ImageButton ID="imgBtnNext" runat="server"
Style="vertical-align: middle;" ImageUrl="next.jpg" 
CommandArgument='<%# Eval("Next")%>' OnClick="click" CommandName="Page" />--%>
</PagerTemplate>
</asp:GridView>

后面的代码是

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DataSet ds = new DataSet();
        SqlDataAdapter adapPaging = new SqlDataAdapter("select * from customer", "Data Source=OPWFMS-7KYGZ7SB;Initial Catalog=Mayank;User ID=sa;Password=sa");
        adapPaging.Fill(ds);

        gridView.DataSource = ds;
        gridView.DataBind();
    }

    public void click1(object send, ImageClickEventArgs e)
    {
        GridViewPageEventArgs obj = new GridViewPageEventArgs(gridView.PageIndex - 1);

        gridView.PageIndex = obj.NewPageIndex;

        LinkButton exmp = new LinkButton();
        exmp.Text = "exmp";
        Panel1.Controls.Add(exmp);
    }

    public void click(object send, ImageClickEventArgs e)
    {
        GridViewPageEventArgs obj = new GridViewPageEventArgs(gridView.PageIndex+1);

        gridView.PageIndex = obj.NewPageIndex;
    }
}

1 个答案:

答案 0 :(得分:0)

您引用的是Panel1,但它未在您提供的代码中的任何位置声明。

还有其他一些代码没有显示出来吗?

如果没有,则错误只是因为您尚未声明Panel1