private DataView  ShowDocbyid(string proid)
{

SqlConnection conn=new SqlConnection(connstring);
string  str="select  '"+proid+"' as ProjectID,(select Project.Name from Project where Project.ID='"+proid+"' group by Project.Name) as ProjectName, c.Name from ObjectDict c where c.ID in (select b.ObjectID from ActionNode b where b.ID in (select a.ActionNodeID from ProjectActionNode a where a.ProjectID ='"+proid+"')) ";
     
SqlCommand comm=new SqlCommand(str,conn);
conn.Open();
SqlDataAdapter da=new SqlDataAdapter(comm);
DataSet ds=new DataSet();
da.Fill(ds,"byid");
DataView dv=ds.Tables["byid"].DefaultView;
    
    conn.Close();
return dv;

}
//显示该工程的文档信息byname;
private DataView ShowDocbyname( string proname)
{
    SqlConnection conn=new SqlConnection(connstring);
string strproid="select ID from Project where Name='"+proname+"'";
            conn.Open();
SqlCommand com=new SqlCommand(strproid,conn);
SqlDataReader dr=com.ExecuteReader();

DataTable dt=new DataTable("byname");
DataColumn dc1=new DataColumn("ProjectID",Type.GetType("System.String"));
DataColumn dc2=new DataColumn("ProjectName",Type.GetType("System.String"));
DataColumn dc3=new DataColumn("Name",Type.GetType("System.String"));
dt.Columns.Add(dc1);
dt.Columns.Add(dc2);
dt.Columns.Add(dc3); while(dr.Read())
{
        SqlConnection newconn=new SqlConnection(connstring);
string  str="select  '"+dr["ID"].ToString()+"' as ProjectID,(select Project.Name from Project where Project.ID='"+dr["ID"].ToString()+"' group by Project.Name) as ProjectName, c.Name from ObjectDict c where c.ID in (select b.ObjectID from ActionNode b where b.ID in (select a.ActionNodeID from ProjectActionNode a where a.ProjectID ='"+dr["ID"].ToString()+"')) ";
    newconn.Open();
SqlCommand newcom=new SqlCommand(str,newconn);
 SqlDataAdapter newda=new SqlDataAdapter(newcom);
 DataSet newds=new DataSet();
 newda.Fill(newds,"row");
           int i=newds.Tables["row"].Rows.Count;
for(int j=0;j<i;j++)
{
DataRow datarow=dt.NewRow();
for(int k=0;k<3;k++)
{
    datarow[k]=newds.Tables["row"].Rows[j][k].ToString();
}
dt.Rows.Add(datarow);
 } }
DataView dv=dt.DefaultView;
              return dv;

     }

private void byname_Click(object sender, System.EventArgs e)
{


}
}
我定义了两个函数,然后在点击byname按钮时,根据两个单选按钮,来选择给DataGrid绑定哪个函数的返回值,可是当发生分页时,页面就会刷新,绑定内容也没了.
这个问题咋解决呀!!????
请高手赐教!!!
谢谢!!!

解决方案 »

  1.   

    但是我是通过单击事件来生成数据源的,刷新后自然没有发生单击事件,自然也就没法绑定了, 
    sunnystar365(淡淡忧伤) 你说的重写一下是啥意思呀!??:)
      

  2.   

    要是能保持住,radiobutton的状态也行!!!
    大家知道如何刷新后还保持刷新前的状态吗!?:)
      

  3.   

    将数据绑定写到一个Sub里。
    然后在要绑定的时候调用Sub不就可以了吗?大多都是这么写的。。
      

  4.   

    你单击的时候数据确实绑定到了该变量中,
    然后它可以做数据源,
    但是DataGird有多页的时候,
    用户点击下一页时,页面刷新,变量也就被清空了,
    因为它是在单击时间中被赋的值呀!!!:(
    因此数据不能被显示了呀!