I have a gridview that is set up to do paging but it is not working correctly.
Only the first page’s control is visible – the other pages have boxes rendered but no control inside them.
Does anyone know why this may be? I have checked that I have more than one page of data.
Thanks,
Oliver
I have attached a screenshot which I hope illustrates my problem.
https://i.stack.imgur.com/NOFnB.jpg
EDIT: source for the gridview
<asp:GridView ID="GridView1" runat="server" OnPageIndexChanging="GridView1_PageIndexChanging"
CssClass="GridView1" OnSelectedIndexChanged="GridView_SelectedIndexChanged"
AllowPaging="True" PageSize="20">
<selectedrowstyle backcolor="LightCyan" forecolor="DarkBlue" font-bold="true" />
</asp:GridView>
it is populated using a dataset generated in c#
EDIT: c# codebehind
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
bindGridView();
}
public void bindGridView()
{
//declare the connection string to use
string connectionString = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
//create sql connection
SqlConnection mySQLconnection = new SqlConnection(connectionString);
//open connection
mySQLconnection.Open();
//define command using text string
SqlCommand mySqlCommand = new SqlCommand(sqlTester, mySQLconnection);
SqlDataAdapter mySqlAdapter = new SqlDataAdapter(mySqlCommand);
//create dataset to fill gridview with
DataSet myDataSet = new DataSet();
mySqlAdapter.Fill(myDataSet);
//fill gridview
GridView1.DataSource = myDataSet;
GridView1.DataBind();
//close the sql connection
mySQLconnection.Close();
}
I think according to your
aspxand your.cs. there is some problem in your css file”GridView1“.Try to remove the css class and tell us . is the problem still exist or not.Note:
It’s not related to your question. but i think you should separate your code in layers instead of writing all the code in your page code behind.
Read about: