Reputation: 333
How to Fetch All The rows of gridview when paging is enabled?.
it is allowing to fetch only current fetch rows not entire gridview rows.
Upvotes: 7
Views: 26820
Reputation: 1
Use following code to get value of e.CommandArgument
. It will solve your issue surely!
protected void GridViewID_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "GetDetail")
{
int index = Convert.ToInt32(e.CommandArgument) % GridViewID.PageSize; // !Important
GridViewRow row = GridViewID.Rows[index];
}
}
Upvotes: 0
Reputation: 1
The solution proposed by "Inside Man" with Page Index is logically correct. But you don't have to use GridView1.SetPageIndex(i); because it just sets the starting row of the current page. You should directly modify GridView1.PageIndex = i;
Upvotes: 0
Reputation: 4319
You can use the Commands Below which I'm using it in my projects. Its logic is so simple, you go through all pages and in every page you go through all rows. You can also get your current page before doing this and after looping all you can get back there ;)
//Get Current Page Index so You can get back here after commands
int a = GridView1.PageIndex;
//Loop through All Pages
for (int i = 0; i < GridView1.PageCount; i++)
{
//Set Page Index
GridView1.SetPageIndex(i);
//After Setting Page Index Loop through its Rows
foreach (GridViewRow row in GridView1.Rows)
{
//Do Your Commands Here
}
}
//Getting Back to the First State
GridView1.SetPageIndex(a);
Upvotes: 13
Reputation: 17194
We disable paging temporarily and will re-bind the grid so that now we have access to all records in the datasource not just current page records.
Once gridview is binded with all records, you can iterate through gridview rows.
Once we are done with our task, we re-enable paging and rebind the grid.
Here the way to tackle with your condition:
protected void Page_Load(object sender, EventArgs e)
{
GridView2.AllowPaging = false;
GridView2.DataBind();
// You can select some checkboxex on gridview over here..
GridView2.AllowPaging = true;
GridView2.DataBind();
}
Upvotes: 8
Reputation: 1526
Before the function of getting the Data from grid just write
yourGridName.AllowPaging=false;
and after getting the Data write
yourGridName.AllowPaging=true;
If your function is GetDataFromGrid() then you should go like this
protected void Page_Load(object sender, EventArgs e)
{
yourGridName.AllowPaging=false;
GetDataFromGrid()
yourGridName.AllowPaging=true;
}
Upvotes: 4
Reputation: 2000
You cant display all rows when paging is enabled.But u can make Allowpaging=false;
in codebehind in pageload or in some event..
protected void Page_Load(object sender, EventArgs e)
{
Gridviewname.AllowPaging=false;
}
or
Protected Void some event(object sender,Eventargs e)
{
Gridviewname.AllowPaging=false;
}
Upvotes: 3
Reputation: 646
Use Following Code And make GridView paging disable
GridView1.AllowPaging = false; GridView1.DataBind();
on Page Load or Some Other event where You Want To show All Your Gridview Rows
Upvotes: 6
Reputation: 2796
Better way is to put a hidden field on the top of the page(outside of gridview) and on click of checkboxes, you should put the related id or some value in comma separated format in hidden field. On submit of the form, you can split the hidden field value string with comma as delimiter and there you go.
Upvotes: 2