Skip to main content
gamedev.net
🔒 Locked 🤖 Godot

[.net] Datagrid paging (webforms) without javascript?

Started by VeryBoringNickName May 25, 2006 at 12:08 PM 3 replies 950+ views
Original Post
VeryBoringNickName
VeryBoringNickName
Simple question: How to make datagrid paging work without &#106avascript? I have a simple datagrid, which gets populated by a dataview, it works perfectly, paging works too, but, as I said, it does only with &#106avascript. I know how to set the index of the grid etc. My Idea would be using my own links (with query-parameters attached &#111;n them, the parameter would transport the position of the targeted page in the grid) I just need basicaly a method with what I can change the links the grid does create &#111;n the &#111;n the back and forwards buttons. The grid uses links like those as back and forward links: <!--STARTSCRIPT--><!--source lang="javascript"--><div class="source"><pre>&lt;a href=<span class="cpp-literal">"javascript:__doPostBack('ctl00$DataGrid1$ctl14$ctl01','')"</span> style=<span class="cpp-literal">"color:#[000066];"</span>&gt;[<span class="cpp-number">2</span>]&lt;/a&gt; </pre></div><!--ENDSCRIPT--> How can I overwrite them?
Strider_Hiryu
Strider_Hiryu
Here's what I did to get paging to work without &#106avascript. I used C# instead.

private void dgAdvanced_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)		{			dgAdvanced.CurrentPageIndex = e.NewPageIndex;			BindGrid(GetResults(GetColumns(), GetConditions()));					}


Essentially, I just run the query that was used to attain the data for the DataGrid again. I setup the properties for the DataGrid to display so many results at once. Whenever a person changed moves ahead, or back inthe data, the index changes, the query is run again, and the result are displayed, starting from that index. The BindGrid Procedure is just what i use to run the query again. Whatever you use to get that information is up to you.
We'll bring your children up in the classic English manner, by making them learn latin, and beating them half to death in a single sex environment.
VeryBoringNickName
VeryBoringNickName
That has nothing to do with my question. I mean that the datagrid generates &#106avascript links (if paging works and is active) on the back and forward buttons/links (or numeric buttons/links).<br/><br/>I want to overwrite those with links of such kind:<br/><br/><br/>DatagridPage.aspx?DatagridPaging=[Insert the paging index number here]
Strider_Hiryu
Strider_Hiryu
this particular article should put you in the right direction. This particular section of the source seems to be what you need.


public static string CreatePagerLinks(PagedDataSource objPds, string BaseUrl){	StringBuilder sbPager = new StringBuilder();	sbPager.Append("More: ");	if (!objPds.IsFirstPage)	{		// first page link		sbPager.Append("|< ");		if (objPds.CurrentPageIndex != 1)		{			// previous page link			sbPager.Append("<<  ");		}	}	// calc low and high limits for numeric links	int intLow = objPds.CurrentPageIndex - 1;	int intHigh = objPds.CurrentPageIndex + 3;	if (intLow < 1) intLow = 1;	if (intHigh > objPds.PageCount) intHigh = objPds.PageCount;	if (intHigh - intLow < 5) while ((intHigh < intLow + 4) && intHigh < objPds.PageCount) intHigh++;	if (intHigh - intLow < 5) while ((intLow > intHigh - 4) && intLow > 1) intLow--;	for (int x = intLow; x < intHigh + 1; x++)	{		// numeric links		if (x == objPds.CurrentPageIndex + 1) sbPager.Append(x.ToString() + "  ");		else		{			sbPager.Append("");			sbPager.Append(x.ToString());			sbPager.Append("  " );		}	}	if (!objPds.IsLastPage)	{		if ((objPds.CurrentPageIndex + 2) != objPds.PageCount)		{			// next page link			sbPager.Append(">>  ");		}		// last page link		sbPager.Append(">|");	}	// conver the final links to a string and assign to labels	return sbPager.ToString();}


The article speaks of a PagedDataSource object. I've never used one before, but it seems to be the way you need to go.
We'll bring your children up in the classic English manner, by making them learn latin, and beating them half to death in a single sex environment.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.