Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
this is a part of my code,
C#
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();

}


and this for grid view
ASP
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False">
    </asp:GridView>


why gridview does not appear in the page ?
Posted
Comments
CHill60 28-Apr-13 7:36am    
Are you checking for postback when you get to the page - otherwise it will default to it's intial state every time

When I do this ...

command = new sqlcommand
using command
set text, type, connection
end



table = new datatable
adapter = new adapter
adapter.selectcommand = command

adapter.fill(table)


Then ...

grid.datasource = table.defaultview
grid.databind

Dispose of everything.

My question to you is why set the datamember? You filled with this table. Use datamember only if you have multiple sources of data. Then you can set the specific table or collection. Did I miss something in your code? :) I am not found very often in ASP.
 
Share this answer
 
Comments
Salah Abualrob 27-Apr-13 9:08am    
it does not work :)
thanks for reply
First check, your table has data.

You can bind gridview with dataset as, first declare a public dataset like

public dataset ds;

C#
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();;



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


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

Try this.
 
Share this answer
 
Comments
Salah Abualrob 27-Apr-13 9:12am    
it does not work too,
thanks for reply :)
First check, your table has data.

You can bind gridview with dataset as, first declare a public dataset like

public dataset ds;

C#
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();;



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


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

Try this.
 
Share this answer
 
First check, your table has data.

You can bind gridview with dataset as, first declare a public dataset like

public dataset ds;

C#
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();;



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


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

Try this.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900