I have a simple task , I have a grid view. I' m having to write the page index changing event to bind the items in the next page to the grid. For this task I' m using this method. This event is fired. It goes through every step of this method and does nothing
meaning it does not get the items for the next page. Can you please help?
Are you programmatically data-binding your GridView? If so, does the Search method set the GridView's DataSource property? The GridView.DataSource property needs be set once againg prior to calling the GridView.DataBind method.
Thanks a lot for your quick response.Yes the search method gets the datatable and search method calls another method binditems whihc binds the datatable to the Grid view and here is the code for the two methods.
DateTime.Parse("1/1/1900");
if (txtFrom.Text !=
"" && !DateTime.TryParse(txtFrom.Text,
out from))
{
updSearchCriteria.Update();
txtFrom.Text = "";
}
to = DateTime.MaxValue;if (txtTo.Text !=
"" && !DateTime.TryParse(txtTo.Text,
out to))
{
updSearchCriteria.Update();
txtTo.Text = "";
}
listFrom = -1000;
if (txtListFrom.Text !=
"" && !decimal.TryParse(txtListFrom.Text,
out listFrom))
{
updSearchCriteria.Update();
txtListFrom.Text = "";
}
listTo = 999999;
if (txtListTo.Text !=
"" && !decimal.TryParse(txtListTo.Text,
out listTo))
{
updSearchCriteria.Update();
txtListTo.Text = "";
}
firstFrom = -1000;
if (txtFirstFrom.Text !=
"" && !decimal.TryParse(txtFirstFrom.Text,
out firstFrom))
{
updSearchCriteria.Update();
txtFirstFrom.Text = "";
}
firstTo = 999999;
if (txtFirstTo.Text !=
"" && !decimal.TryParse(txtFirstTo.Text,
out firstTo))
{
updSearchCriteria.Update();
txtFirstTo.Text = "";
}
int division = 0;
int category = 0;
int classVal = 0;
int line = 0;
int.TryParse(ddlDivision.SelectedValue,
out division);
int.TryParse(ddlCategory.SelectedValue,
out category);
int.TryParse(ddlClass.SelectedValue,
out classVal);
int.TryParse(ddlLine.SelectedValue,
out line);
DataTable dt =
DAItem.SearchItems(txtDescription.Text, txtFullStyleNum.Text,
int.Parse(ddlMarketCode.SelectedValue),
hey mate.. i think i'm the same issue as you did... i'm trying to bind the datagrid from excel file.. when I click on the page number, it doesn't display anything. I know i have to re-bind the datasource but how do i achieve this? do I need to open connection
for that excel again?
If that connection is closed. But just to bind the data you should not have to worry about the connection if there is a method fetching this dataset for you. If you have written it all in the code behind file ...
even then I would say put the lines of code fetching the data set into a method and call it as many times as you want to bind the data. That way the code is more readable and it also reduces the lines of repititive code. Hope I answered your question.
mate... thanks for the help.. one more question, would that be in-efficient if you have to open and close the connection every time changing page? as far I'm aware it would consume the network bandwith (depends on how big the dataset is)? am i right?
Amulu
Member
118 Points
251 Posts
GridView Page index changing
May 22, 2008 06:14 PM|LINK
Hello,
I have a simple task , I have a grid view. I' m having to write the page index changing event to bind the items in the next page to the grid. For this task I' m using this method. This event is fired. It goes through every step of this method and does nothing meaning it does not get the items for the next page. Can you please help?
thanks
Mythili
protected void gvSearchItems_PageIndexChanging(object sender, GridViewPageEventArgs e){
Search(); //I' m using this method to find all the items I need to be posted in my grid.
gvSearchItems.PageIndex = e.NewPageIndex ;
gvSearchItems.DataBind();
}
ecbruck
All-Star
98783 Points
9691 Posts
Moderator
Re: GridView Page index changing
May 22, 2008 06:23 PM|LINK
Are you programmatically data-binding your GridView? If so, does the Search method set the GridView's DataSource property? The GridView.DataSource property needs be set once againg prior to calling the GridView.DataBind method.
Microsoft MVP - ASP.NET
Amulu
Member
118 Points
251 Posts
Re: GridView Page index changing
May 22, 2008 06:34 PM|LINK
Thanks a lot for your quick response.Yes the search method gets the datatable and search method calls another method binditems whihc binds the datatable to the Grid view and here is the code for the two methods.
Thanks again
private void BindItems(DataView dt){
gvSearchItems.DataSource = dt;
gvSearchItems.PageSize = Profile.ItemResutsPerPage;
gvSearchItems.DataBind();
dlSearchItems.DataSource = dt;
dlSearchItems.DataBind();
if (dt.Count > 0){
int from, to;from = Profile.ItemResutsPerPage * gvSearchItems.PageIndex + 1;
if (from + Profile.ItemResutsPerPage - 1 > dt.Count)to = dt.Count;
elseto = from + Profile.ItemResutsPerPage - 1;
lblResults.Text = from.ToString() + "-" + to.ToString() + " of " + dt.Count.ToString() + " Results";lblResults.Visible = true;}
else{
lblResults.Visible = false;}
}
//My search method.
private void Search(){
switch (RadioButtonList1.SelectedValue){
case "0":gvSearchItems.Columns[1].Visible =
true; gvSearchItems.Visible = true;dlSearchItems.Visible =
false; break; case "1": gvSearchItems.Columns[1].Visible = false;gvSearchItems.Visible =
true; dlSearchItems.Visible = false; break; case "2":gvSearchItems.Visible =
false; dlSearchItems.Visible = true; break; default:break;}
DateTime from, to; decimal listFrom, listTo, firstFrom, firstTo;from =
DateTime.Parse("1/1/1900"); if (txtFrom.Text != "" && !DateTime.TryParse(txtFrom.Text, out from)){
updSearchCriteria.Update();
txtFrom.Text = "";}
to = DateTime.MaxValue;if (txtTo.Text != "" && !DateTime.TryParse(txtTo.Text, out to)){
updSearchCriteria.Update();
txtTo.Text = "";}
listFrom = -1000;
if (txtListFrom.Text != "" && !decimal.TryParse(txtListFrom.Text, out listFrom)){
updSearchCriteria.Update();
txtListFrom.Text = "";}
listTo = 999999;
if (txtListTo.Text != "" && !decimal.TryParse(txtListTo.Text, out listTo)){
updSearchCriteria.Update();
txtListTo.Text = "";}
firstFrom = -1000;
if (txtFirstFrom.Text != "" && !decimal.TryParse(txtFirstFrom.Text, out firstFrom)){
updSearchCriteria.Update();
txtFirstFrom.Text = "";}
firstTo = 999999;
if (txtFirstTo.Text != "" && !decimal.TryParse(txtFirstTo.Text, out firstTo)){
updSearchCriteria.Update();
txtFirstTo.Text = "";}
int division = 0; int category = 0; int classVal = 0; int line = 0; int.TryParse(ddlDivision.SelectedValue, out division); int.TryParse(ddlCategory.SelectedValue, out category); int.TryParse(ddlClass.SelectedValue, out classVal); int.TryParse(ddlLine.SelectedValue, out line); DataTable dt = DAItem.SearchItems(txtDescription.Text, txtFullStyleNum.Text, int.Parse(ddlMarketCode.SelectedValue),division, category, classVal, line,
ddlDesigners.SelectedValue, ddlMerchandisers.SelectedValue, int.Parse(ddlStoneName.SelectedValue),txtStoneName.Text, int.Parse(ddlPresentation.SelectedValue), int.Parse(ddlTheme.SelectedValue), int.Parse(ddlVendors.SelectedValue), int.Parse(ddlSampleStatus.SelectedValue),from, to, listFrom, listTo, firstFrom, firstTo, txtCustomerProposal.Text, txtPONum.Text);
DataView dv = new DataView(dt);dv.Sort =
string.Format("{0} {1}", ViewState["SortExpression"], ViewState["SortDirection"]); Profile.ItemResutsPerPage = int.Parse(ddlResultsPerPage.SelectedValue);BindItems(dv);
}
Amulu
Member
118 Points
251 Posts
Re: GridView Page index changing
May 22, 2008 08:25 PM|LINK
I found out... [:)]
Thid gridview was in an update panel with updatemode as conditional so I had to add the async postback event as Databinding for the GridView.
ronald_yoh
Member
108 Points
519 Posts
Re: GridView Page index changing
Nov 12, 2008 11:50 PM|LINK
hey mate.. i think i'm the same issue as you did... i'm trying to bind the datagrid from excel file.. when I click on the page number, it doesn't display anything. I know i have to re-bind the datasource but how do i achieve this? do I need to open connection for that excel again?
Thanks
Amulu
Member
118 Points
251 Posts
Re: GridView Page index changing
Nov 13, 2008 03:42 PM|LINK
If that connection is closed. But just to bind the data you should not have to worry about the connection if there is a method fetching this dataset for you. If you have written it all in the code behind file ...
even then I would say put the lines of code fetching the data set into a method and call it as many times as you want to bind the data. That way the code is more readable and it also reduces the lines of repititive code. Hope I answered your question.
Thanks
ronald_yoh
Member
108 Points
519 Posts
Re: GridView Page index changing
Nov 13, 2008 08:44 PM|LINK