我刚学.NET,现在遇到这样一个问题
就是在一个界面上放了两个以上的DataGrid显示同根据条件同时显示同一个表的内容。请问怎样解决
代码如下:public class index : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid dyinfo;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
SqlConnection co=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["dbConnection"]);

private void Page_Load(object sender, System.EventArgs e)
{
//显示百商财富            co.Open();SqlCommand cmd=new SqlCommand("select top 4      UName,ProName,UserId from v_tty_proInfo where Lbname='百商财富' order by  Sdate Desc",co);
DataGrid1.DataSource=cmd.ExecuteReader();
DataGrid1.DataBind();
//显示抵押贷款' SqlCommand cmd=new SqlCommand("select top 4 UName,ProName,UserId from v_tty_proInfo where Lbname='抵押贷款' order by  Sdate Desc",co);
DataGrid2.DataSource=cmd.ExecuteReader();
DataGrid2.DataBind();

解决方案 »

  1.   

    SqlCommand cmd1=new SqlCommand("select top 4      UName,ProName,UserId from v_tty_proInfo where Lbname='百商财富' order by  Sdate Desc",co);SqlDataAdapter da = new SqlDataAdapter(cmd1);
    DataSet ds = new DataSet();
    da.Fill(ds,"nu1");
    DataGrid1.DataSource=ds.Tables["nu1"].DefaultView;
    DataGrid1.DataBind();SqlCommand cmd2=new SqlCommand("select top 4 UName,ProName,UserId from v_tty_proInfo where Lbname='抵押贷款' order by  Sdate Desc",co);
    da.SelectCommand = cmd2;
    da.Fill(ds,"nu2");
    DataGrid2.DataSource=ds.Tables["nu2"].DefaultView;
    DataGrid2.DataBind();这样试试
      

  2.   

    回复人: biao88482005(飚) 谢谢你给我的解答。运行是可以了,
    如果我在DataGrid只显示UName和ProName并且固定UName和ProName的宽度分别为25%和75%。由于ProName的字段比较多,显示时数据就自动换行了,我想不让它换行,如果没显示的就省了。这样怎样实现啊。请赐教!