ramrod1979
asked on
index out of range
Hi
I'm using paging on my datagrid but have run into the following problem, when I choose to go to the next page I get the following error: Specified argument was out of the range of valid values. Parameter name: index. I am using a viewstate variable that I'm passing to my bindgrid method in order to get the date range that I want to occupy in my datagrid. So my bindgrid method looks like the following:
private void bindGrid()
{
sqlConnection1.Open();
sqlDataAdapter1.SelectComm and.Comman dText="sel ect * from mainTABLE where [date]='"
+ViewState["dateWorked"] +"'";
sqlDataAdapter1.Fill(dataS et1);
sqlDataAdapter2.Fill(agMai n1);
DataGrid1.DataBind();
DataGrid1.DataSource=dataS et1;
sqlConnection1.Close();
}
I use two datasets because the datagrid has two drop down list that are occupied with selections from another table.
The page changed event is the standard one as follows:
private void changePage(object source, System.Web.UI.WebControls. DataGridPa geChangedE ventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
bindGrid();
}
And the view selected date gets the date range to load into the bindgrid method from the calendar control as follows:
private void viewSelectedDate(object sender, System.EventArgs e)
{
ViewState["dateWorked"] = Calendar1.SelectedDate.ToL ongDateStr ing();
bindGrid();
}
What am I missing? What have I done wrong?
I'm using paging on my datagrid but have run into the following problem, when I choose to go to the next page I get the following error: Specified argument was out of the range of valid values. Parameter name: index. I am using a viewstate variable that I'm passing to my bindgrid method in order to get the date range that I want to occupy in my datagrid. So my bindgrid method looks like the following:
private void bindGrid()
{
sqlConnection1.Open();
sqlDataAdapter1.SelectComm
+ViewState["dateWorked"] +"'";
sqlDataAdapter1.Fill(dataS
sqlDataAdapter2.Fill(agMai
DataGrid1.DataBind();
DataGrid1.DataSource=dataS
sqlConnection1.Close();
}
I use two datasets because the datagrid has two drop down list that are occupied with selections from another table.
The page changed event is the standard one as follows:
private void changePage(object source, System.Web.UI.WebControls.
{
DataGrid1.CurrentPageIndex
bindGrid();
}
And the view selected date gets the date range to load into the bindgrid method from the calendar control as follows:
private void viewSelectedDate(object sender, System.EventArgs e)
{
ViewState["dateWorked"] = Calendar1.SelectedDate.ToL
bindGrid();
}
What am I missing? What have I done wrong?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
private void BindGrid()
{
BindGrid(0);
}
private void BindGrid(int index)
{
sqlConnection1.Open();
sqlDataAdapter1.SelectComm
+ViewState["dateWorked"] +"'";
sqlDataAdapter1.Fill(dataS
sqlDataAdapter2.Fill(agMai
DataGrid1.CurrentPageIndex
DataGrid1.DataSource=dataS
DataGrid1.DataBind();
sqlConnection1.Close();
}
private void changePage(object source, System.Web.UI.WebControls.
{
BindGrid(e.NewPageIndex);
}
private void viewSelectedDate(object sender, System.EventArgs e)
{
ViewState["dateWorked"] = Calendar1.SelectedDate.ToL
BindGrid();
}