Showing posts with label tutorial. Show all posts
Showing posts with label tutorial. Show all posts

Saturday, March 24, 2012

Paging using DataGrid and DataList (referring to ScottGus paging tutorial)

I have a webpage that uses a Datalist adapted from ScottGu's example athttp://weblogs.asp.net/scottgu/archive/2006/01/07/434787.aspx. It does not seem to benefit from Ajax partial updates (update panel), since as it pages, it actually asks for different pages' urls, etc...(Please see ScottGu's fantastic tutorial there for more details).

Question: If I use a DataGrid that has paging turned on, will it (magically) perform the operations mentioned in Scott's article, that is, sending only that data through each page request that is pertinet to that page?

Question 2 There is a slim chance that ASP.Net Ajax is actually so smart as to do what I said above, however, I need a DataList (for formatting reasons) that does not have paging .

Is there a way for the paging mentioned in ScottGu's article to be applied to the asynchornous paging, and for the paging control on the page (a hyperlink) to fetch data from that stored "stash"?

Thanks,

Paolo

Dogs Rule!

Just glancing through Scott's post, it doesn't look like this will "just work" inside an UpdatePanel, because as you mention, it's requesting a new page URL with the page number in the query string.

To get something like this to work, you'd need to first convert it to use postbacks instead of page navigation. (So change the hyperlink to a HyperLinkButton and pass the page number as an argument to the event handler instead of as a query string parameter.)

Basically, if you have a page that works with postbacks, it should be easy to use UpdatePanels to get AJAX functionality. If you have navigation, however (new URLs), then the UpdatePanel won't help you.


View this code

CODE
Sub BindData()
Dim mydt As New yourdatable()
Dim tba As NewyourobjectTableAdapters.yourtableadaper()


tba.Fill(mydt, Me
dgPager.CurrentPageIndex * Me.dgPager.PageSize , Me.dgPager.PageSize)

Me.dgPager.VirtualItemCount = yourqueryrecordcount

Me.
dgPager.DataSource = mydt
Me.
dgPager.DataBind()

Me.DataList1.DataSource = mydt
Me.DataList1.DataBind()

End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Not Page.IsPostBack Then
BindData()

End If
End Sub

Protected Sub dgPager_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
e.Item.Visible = False
End If

End Sub

ProtectedSub dgPager_PageIndexChanged(ByVal source As Object, ByVal e AsSystem.Web.UI.WebControls.DataGridPageChangedEventArgs)
Me.dgPager.CurrentPageIndex = e.NewPageIndex
BindData()

End Sub
ASPX page

<form id="form1" runat="server">
<asp:DataList ID="DataList1" runat="server" RepeatColumns="4" RepeatDirection="Horizontal">
<ItemTemplate>
<%# Eval("YourDataField") %><br />
</ItemTemplate>
</asp:DataList>
<asp:DataGridID="dgPager" runat="server" AllowPaging="True"AutoGenerateColumns="False" GridLines="None" PageSize="8"ShowHeader="False" OnPageIndexChanged="dgPager_PageIndexChanged"OnItemCreated="dgPager_ItemCreated" AllowCustomPaging="True">
<PagerStyle Mode="NumericPages" />
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

</form>

Wednesday, March 21, 2012

partial page rendering with master page... and a broken link in the tutorial

I can't for the life of me figure out how to enable partial page rendering with the newest AJAX release (including the nov. CTP)...

the tutorial speaks to it "If you are working with master pages, you might need to use aScriptManagerProxy control in place of aScriptManager control. For more information, seeHow to: Use Partial-Page Updates in Master Pages.", but you'll notice the link leads to a 404 error.

anyone know the answer to this? I've tried replacing my script manager with a script manager proxy, but the page complains that it needs a script manager first... I'm lost.

Cheers

place the scriptmanager on the masterpage.

place the scriptmanagerproxy on each content page.


you wouldn't happen to have a code example of how to use the proxy manager, would you?

In the Master page, it would be like

<form runat="server">
<asp:ScriptManager id="sm1" runat="server" /
... rest of masterpage markup

</form>

In the content page

<asp:ScriptManagerProxy ID="smp1" runat="server">
<Services>
<asp:ServiceReference Path="~/common/services/ReportData.asmx" />
</Services>
</asp:ScriptManagerProxy>


yeah, that's kinda what I thought... unfortunately (for me!), it's still refreshing the whole page...

hmm... maybe a little more explanation of the page...

I have the script manager in the master page, the proxy manager is in the content page. Also in the content page, I have a GridView in an UpdatePanel. The update panel has an AsyncPostBackTrigger setup on a timer tick, so, I obviously also have a timer on the page (not IN the update panel, it's actually just above it). This used to work perfectly, the grid view would update without refreshing the whole page, users were happy (a near impossibility!), everything was hunky-dory... then I decided to upgrade <grin>.

Any help would be awesome.

Cheers


i dont know why you just don't put the Timer inside the UpdatePanel's Content template, but i'd suggest trying that...

Also this post:
http://forums.asp.net/thread/1452109.aspx

Solved a timer issue i had


wonderbar... works perfectly now.

thanks!


I tried this. It still complains about unknown element 'ScriptMangerProxy'. Any idea why is that? But strange thing is: it compiled.

mbanavige:

place the scriptmanager on the masterpage.

place the scriptmanagerproxy on each content page.

partial page update in a usercontrol on a master page

OK, I've installed AJAX Extensions, watched the tutorial video and tried to use the partial page update as follows: I have a user control which contains hyperlinks for paging back and forth and a datalist which displays the current page of products: <asp:UpdatePanelID="UpdatePanel1"runat="server"> <ContentTemplate> <asp:HyperLinkID="hLink_Previous"CssClass="paging_Text"Visible="false"runat="server">Previous</asp:HyperLink> <asp:LabelID="label_Paging"CssClass="paging_Text"Visible="false"runat="server"/> <asp:HyperLinkID="hLink_Next"CssClass="paging_Text"Visible="false"runat="server">Next</asp:HyperLink> <asp:DataListID="dataList_Products"RepeatColumns="2"RepeatDirection="Horizontal"runat="server"EnableViewState="False"OnItemCommand="dataList_Products_ItemCommand"> <ItemTemplate> <tableclass="dataList_Products_Table"cellpadding="0"align="left"> <trclass="dataList_Products_Table_Row"> <tdalign=centerclass="dataList_Products_Table_Cell_1"> <ahref='Product.aspx?P=<%# Eval("ProductID")%>'> <imgclass="small_Image"src='ProductImages/<%# Eval("Image1FileName")%>'/> </a> </td> <tdclass="dataList_Products_Table_Cell_2"> <aclass="product_Name"href='Product.aspx?P=<%# Eval("ProductID")%>'> <%# Eval("Name")%> </a> <br/> <spanclass="product_Description"> <%# Eval("Description")%> <br/> <br/> Price: </span> <spanclass="product_Price"> <%# Eval("Price","{0:C}")%> </span> <br/> <asp:ButtonID="btn_AddToCart"Text="Add to Cart"CssClass="small_Button_Text"CommandArgument='<%# Eval("ProductID")%>'runat="server"/> </td> </tr> </table> </ItemTemplate> </asp:DataList> </ContentTemplate></asp:UpdatePanel> I use this within the contentPlaceHolder on the Master page. I want only this bit to update when I navigate between pages but looking at the triggers collection, I can only see the datalist and ScriptManager controls - how do I hook into the previous and next page hyperlinks and their onClick event to enable the page update ? Thanks AR

Hi,

HyperLink control doesn't have click event.

You can use LinkButton control that has a similar layout like hyperlink to achieve so.

Hope this helps.