Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fixed pager position within Gridview?

Status
Not open for further replies.

FancyPrairie

Programmer
Oct 16, 2001
2,917
US
I have a gridview with a horizontal scrollbar. The paging modes (i.e. next, previous, 1, 2,3...) can either be positioned on the left, center, right, or justify. If I set the HorizontalAlign property of the pager to center, then I have to scroll to see the pager modes. If I set the property to left and scroll to the right, then when I scroll to the right I can't see the pager modes and must scroll back to the left to select one.

How can I set the paging mode so that they are always shown no matter how far I scroll to the right or left?
 
I don't belive you can. Where they are displayed is fixed, like you said, either left,right or center. To do what you want, you would need to make the pager "float" somehow. If you find a way please post.


Jim
 
That's what I figured. Is there a way to programmatically execute a pager event? For example, suppose I had a next button (independant of the gridview) and when selected the next button of the pager would fire?
 
You could call the event, but it is kind of clumsy and .NET really doesn't want you to do it that way. Other languages allow that easily (I used to do it in Power Builder).

What I suggest is just to write code in the button click that would increment the pageindex (and check that you are not beyond the total number of pages). Then in the pageindexchaned event, write any commen code you want to run when the index changes.

Jim
 
Here's my problem. I can't figure out how to reference the pageindex. I added a button (outside of the gridview) and via the Onclick event added the following code:

FormView1_GridView1.PageIndex = FormView1_GridView1.PageIndex + 1

However, although (via debug) FormView1_GridView1.ID does display correctly, the page bombs at the line of code above. So, how do I reference the PageIndex?
 
What do you mean it bombs? What is the error? Is your gridview inside of a formview?
 
You should be able to do this by referencing the PageCount property. I have a grid named dg1. I added a couple of buttons and wired them up to handle the paging. Works fine:
Code:
private void Button1_Click(object sender, System.EventArgs e)
{
	// if the current page + 1 will be less than the PageCount
	// then increment and rebind
	if(dg1.CurrentPageIndex+1 < dg1.PageCount)
	{
	dg1.CurrentPageIndex++;
	BindGrid();
	}
}

private void Button2_Click(object sender, System.EventArgs e)
{
	// if we're not at the first page then decrement and rebind
	if(dg1.CurrentPageIndex != 0)
	{
	dg1.CurrentPageIndex--;
	BindGrid();
	}
}


Vince
 
The error message I'm receiving is "Object doesn't support this method or property". However, you picked up correctly that I had the gridview within a formview. (Newbie stupidity). I'm attempting to simulate tabs by placing a formview within a panel and a gridview within another panel. Then just toggle the visibility of the panels. So now I have separated the gridview from the formview and can reference Gridview1.ID correctly, but no GridView1.PageIndex. Same error message.

Vince, are your buttons within the gridview or outside of the gridview?
 
If the grid is now outside of the formview you should be able to access gridview1.pageindex

The problem is you have nested controls. If you have the grid nested in the formview, you will need to use the DataBound event of the fromview to get a reference to the gridview.

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top