private void BindGrid1()
{
 string strConn=ConfigurationSettings.AppSettings["strConnection"];
 SqlConnection mycn= new SqlConnection(strConn);
 mycn.Open();
 for(int i=0;i<this.ShowMateriaList.Items.Count;i++)
  {
   Label  label=(Label) ShowMateriaList.Items[i].FindControl("Ssort");
   string strsql3="select ID from SecondSort where Ssort='"+label.Text+"'";
   SqlCommand cn= new SqlCommand(strsql3,mycn);
   int d=(int)cn.ExecuteScalar();

   DataGrid myGrid =(DataGrid) this.ShowMateriaList.Items[i].FindControl("DGShowThirdSort");
   string strsql2="select ID,Tsort from ThirdSort where SecondID='"+d+"'";
   SqlCommand cn2= new SqlCommand(strsql2,mycn);
   SqlDataAdapter da=new SqlDataAdapter();
   da.SelectCommand=cn2;
   DataSet ds=new DataSet();
   da.Fill(ds);
   myGrid.DataSource=ds;
   myGrid.DataKeyField = "ID";
   myGrid.DataBind();   string myKeyid = "";
   for(int j=0;j<myGrid.Items.Count;j++)
{
  myKeyid = myGrid.DataKeys[j].ToString();
  LinkButton myBut = (LinkButton)myGrid.Items[j].Cells[0].Controls[0];
  myBut.Attributes.Add("onclick","window.open('show1.aspx?user_id=" + myKeyid + "','','')"); } 
 }
mycn.Close();
}上面这段函数,能把表ThirdSort 所选定的ID以user_id=" + myKeyid + "' 方式传到show1页面.
那我想把表SecondSort 所选定的ID 也传到show1页面,应该怎么做呢?SecondSort的数据绑定在label上.
ThirdSort的数据绑定在datagrid上.
 

解决方案 »

  1.   

    myBut.Attributes.Add("onclick","window.open('show1.aspx?user_id="+myKeyid+"+"&id="+"+d+"','','')");
      

  2.   

    "&id="  这个值是那里的?是show1页面,还是当前页面.
    运行时,系统错误提示为C:\Inetpub\wwwroot\NetTeacher\ShowMateria.aspx.cs(120): 名称“id”在类或命名空间“NetTeacher.ShowMateria”中不存在
      

  3.   

    myBut.Attributes.Add("onclick","window.open('show1.aspx?user_id="+myKeyid+"+"&id="+"+d+"','','')");
    &id是你要传递过去的参数名
    d是int d=(int)cn.ExecuteScalar();//参数值
      

  4.   

    myBut.Attributes.Add("onclick","window.open('show1.aspx?user_id="+myKeyid+"+&id=+"+d+"','','')");
    这样试试
      

  5.   

    那在show1怎么读取这个 &id值呢?
    我现在是用 Request["&id"] 这句话, 但不能读出.
    那正确是应该用什么语句?
      

  6.   

    Request.QueryString["id"] 
    或者
    Request["id"]