日期:2014-05-18  浏览次数:20449 次

还是传值问题
C# code

  protected void Page_Load(object sender, EventArgs e)
    { 
        if(!IsPostBack)
        {
           // bind();
              bindDT();
              if (Request.QueryString["zid"] != null)
              {
                  int zid = Convert.ToInt32(Request.QueryString["zid"].ToString());
                  DataTable dt2 = Bmer.GetFMSbyid(zid).Tables[0];
                  this.Repeater2.DataSource = dt2;
                  this.Repeater2.DataBind();             
              }
            if(Request.QueryString["notid"]!=null)
            {
                int notid = Convert.ToInt32(Request.QueryString["notid"].ToString());
                this.GridView3.DataSource = Bmer.GetPyByid(notid).Tables[0];
                this.GridView3.DataBind();
            }


        }
    }

    private void bindDT()
    {
        DataTable dt = Bmer.GetAllname().Tables[0];
        this.Repeater1.DataSource = dt;
        this.Repeater1.DataBind();
    }



C# code

 <div>
    
    
        <asp:Repeater ID="Repeater1" runat="server">
        <HeaderTemplate><table border="1"><tr><td>比赛名称</td></HeaderTemplate>
        <ItemTemplate>
                       <td>  <a href='Default.aspx?zid=<%#Eval("zid") %>'>
                             <%#Eval("zname")%>
                        </a>

                     </td>
    
        </ItemTemplate>
        <FooterTemplate></tr></table></FooterTemplate>
        </asp:Repeater>

        <br />
        <br />
        <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False">
            <Columns>
                <asp:BoundField DataField="id" HeaderText="id" Visible="False" />
                <asp:BoundField DataField="name" HeaderText="比赛名称" />
                <asp:BoundField DataField="zid" HeaderText="zid" Visible="False" />
            </Columns>
        </asp:GridView>

        <asp:Repeater ID="Repeater2" runat="server">
        <HeaderTemplate><table border="1"><tr><td>分类比赛</td></HeaderTemplate>
        <ItemTemplate>
        <td><a href='Default.aspx?notid=<%#Eval("notid") %>'>
            <%#Eval("name")%>
           </a>
           </td>
    
        </ItemTemplate>
        <FooterTemplate></tr></table></FooterTemplate>
        </asp:Repeater>
        <br />
        <br />
        <asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False">
            <Columns>
                <asp:BoundField DataField="id" HeaderText="id" Visible="False" />
                <asp:BoundField DataField="name" HeaderText="选手" />
                <asp:BoundField DataField="notid" HeaderText="notid" Visible="False" />
            </Columns>
        </asp:GridView>
        <br />
        <br />

    </div>




网页打开时,显示repeater数据 比赛名称,点击分类比赛的时候显示选手出来

问题:当page里加了if(!IsPostBack)由于页面刷新 地址栏可以显示传到页面的值notid 但gridview3不显示
但如果去掉if的话 可以显示gridview3 但repeater2 分类比赛不显示了 
如何解决?

------解决方案--------------------