本文介绍了如何将ds绑定到gridview?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我的代码的一部分,

Hi,
this is a part of my code,

if (Session["MenuItem"] != null)
{
    string s = Session["MenuItem"].ToString();
    int TypeId = getTypeId(Session["MenuItem"].ToString());
    Adapter = new SqlDataAdapter("SELECT Title,Date,Time,AgeId FROM Subjects WHERE CId = '"+TypeId+"'", con);
    Adapter.Fill(ds, "Subjects");
    GridView1.DataSource = ds;
    GridView1.DataMember = "Subjects";
    GridView1.DataBind();
    GridView1.Visible = true;
    Label3.Text = ds.Tables[0].Rows.Count.ToString();
    //DataTable dt = ds.Tables[0];
    //Adapter.Fill(dt);
    //GridView1.DataSource = dt;
    //GridView1.DataBind();

}





和this for网格视图



and this for grid view

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False">
    </asp:GridView>





为什么gridview没有出现在页面中?



why gridview does not appear in the page ?

推荐答案


string s = Session["MenuItem"].ToString();
int TypeId = getTypeId(Session["MenuItem"].ToString());
Adapter = new SqlDataAdapter("SELECT Title,Date,Time,AgeId FROM Subjects WHERE CId = '"+TypeId+"'", con);
Adapter.Fill(ds, "Subjects")
  GridView1.DataBind();;










<asp:GridView DataSource='<%#ds>' ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False">
    </asp:GridView>





你可以在源头注意到我有为gridview添加了DataSource属性



试试这个。



as you can notice in source i have added DataSource property for gridview

Try this.


string s = Session["MenuItem"].ToString();
int TypeId = getTypeId(Session["MenuItem"].ToString());
Adapter = new SqlDataAdapter("SELECT Title,Date,Time,AgeId FROM Subjects WHERE CId = '"+TypeId+"'", con);
Adapter.Fill(ds, "Subjects")
  GridView1.DataBind();;










<asp:GridView DataSource='<%#ds>' ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False">
    </asp:GridView>





你可以在源头注意到我有为gridview添加了DataSource属性



试试这个。



as you can notice in source i have added DataSource property for gridview

Try this.


这篇关于如何将ds绑定到gridview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 21:07