Showing posts with label paging. Show all posts
Showing posts with label paging. Show all posts

Wednesday, March 28, 2012

LinkButton inside a repeater as a trigger

 I have been searching all over for an answer but have yet to find anything. 

I have a repeater that I use to display a letter paging system. It looks something like this

<asp:Repeater ID="rpt_Letters" runat="server"> <ItemTemplate> <asp:LinkButton ID="lbtn_Letter" CausesValidation="false" CommandName="Filter" CommandArgument='<%# Eval("Letter") %>' runat="server" style="padding-left:7px; padding-top: 10px;" ToolTip='<%# Eval("Letter") %>'><%# Eval("Letter") %></asp:LinkButton> </ItemTemplate> </asp:Repeater>

Once a letter is clicked I want to update the information in a GridView.

I have the GridView in an update panel, but I can't find away to set my Letter Paging as a trigger.

Thank You!


.csharpcode, .csharpcode pre{font-size: small;color: black;font-family: Consolas, "Courier New", Courier, Monospace;background-color: #ffffff;/*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op { color: #0000c0; }.csharpcode .preproc { color: #cc6633; }.csharpcode .asp { background-color: #ffff00; }.csharpcode .html { color: #800000; }.csharpcode .attr { color: #ff0000; }.csharpcode .alt {background-color: #f4f4f4;width: 100%;margin: 0em;}.csharpcode .lnum { color: #606060; }
Add your repeater control to an UpdatePanel as follows:<asp:UpdatePanelID="PagingPanel"UpdateMode="Conditional"runat="server"><ContentTemplate><asp:RepeaterId="">...</asp:Repeater>and put your gridview control in another UpdatePanel like this:<asp:UpdatePanelID="OrderDetailsPanel"UpdateMode="Always"runat="server"><ContentTemplate><asp:gridview/>And then add handler for OnCommand event of the linkbutton (lbtn_Letter) where you can filter rows like this:protected void Letter_OnCommand(object sender, CommandEventArguments e) { SqlDataSource2.SelectParameters["OrderID"].DefaultValue = e.CommandArgument ;SqlDataSource2.DataBind();}where SqlDataSource2 is bound to your GridView control.That's it.

Thanks!

LinkButton Trigger inside a repeater

 I have been searching all over for an answer but have yet to find anything. 

I have a repeater that I use to display a letter paging system. It looks something like this

<asp:Repeater ID="rpt_Letters" runat="server"> <ItemTemplate> <asp:LinkButton ID="lbtn_Letter" CausesValidation="false" CommandName="Filter" CommandArgument='<%# Eval("Letter") %>' runat="server" style="padding-left:7px; padding-top: 10px;" ToolTip='<%# Eval("Letter") %>'><%# Eval("Letter") %></asp:LinkButton> </ItemTemplate> </asp:Repeater>

Once a letter is clicked I want to update the information in a GridView.

I have the GridView in an update panel, but I can't find away to set my Letter Paging as a trigger.


Hi,

an approach could be wrapping the repeater with an UpdatePanel with UpdateMode="Conditional" and ChildrenAsTriggers="false". This won't make the panel update when a LinkButton is clicked, but will trigger an asynchronous postback where you can update the panel that contains the GridView. Check this basic example:

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { repTriggers.DataSource = new int[3] { 0, 1, 2 }; repTriggers.DataBind(); } } protected void repTriggers_ItemCommand(object sender, RepeaterCommandEventArgs e) { if (e.CommandName == "trigger") { LinkButton btn = e.CommandSource as LinkButton; if (btn != null) { lblUpdate.Text = "Update triggered by " + btn.ID + e.Item.ItemIndex.ToString(); } UpdatePanel2.Update(); } }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="TheScriptManager" runat="server"></asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="false" UpdateMode="conditional"> <ContentTemplate> <asp:Repeater ID="repTriggers" runat="server" OnItemCommand="repTriggers_ItemCommand"> <ItemTemplate> <asp:LinkButton ID="lnkTrigger" runat="server" Text="Trigger" CommandName="trigger"></asp:LinkButton> </ItemTemplate> </asp:Repeater> </ContentTemplate> </asp:UpdatePanel> <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="conditional"> <ContentTemplate> <asp:Label ID="lblUpdate" runat="server"></asp:Label> </ContentTemplate> </asp:UpdatePanel> </form></body></html>

Good suggestion, Garbin, but I think I have an even easier way. You can simply add your Repeater as a trigger for your UpdatePanel. Here's my version, with comments indicating where it differs from Garbin's:

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { repTriggers.DataSource = new int[3] { 0, 1, 2 }; repTriggers.DataBind(); } } protected void repTriggers_ItemCommand(object sender, RepeaterCommandEventArgs e) { if (e.CommandName == "trigger") { LinkButton btn = e.CommandSource as LinkButton; if (btn != null) { lblUpdate.Text = "Update triggered by " + btn.ID + e.Item.ItemIndex.ToString(); } // [Steve] removed UpdatePanel2.Update() } }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head id="Head1" runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="TheScriptManager" runat="server"></asp:ScriptManager><%-- [Steve] removed UpdatePanel1 --%> <asp:Repeater ID="repTriggers" runat="server" OnItemCommand="repTriggers_ItemCommand"> <ItemTemplate> <asp:LinkButton ID="lnkTrigger" runat="server" Text="Trigger" CommandName="trigger"></asp:LinkButton> </ItemTemplate> </asp:Repeater> <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="conditional"><%-- [Steve] added repTriggers as an AsyncPostBackTrigger --%> <Triggers> <asp:AsyncPostBackTrigger ControlID="repTriggers" /> </Triggers> <ContentTemplate> <asp:Label ID="lblUpdate" runat="server"></asp:Label> </ContentTemplate> </asp:UpdatePanel> </form></body></html>

Hi,

yes, definitely :)


Thank you!

That was too easy! I can't believe I never tried that.Embarrassed

Saturday, March 24, 2012

listView paging and sorting

Will paging and sorting features be added to the listView control or will that be left to each developer to implement?
Thanks,
KeeganThey will. I can't tell you when but they will.