473,320 Members | 1,957 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Why is it so difficult to fire itemcommand events in a repeater?

I have a repeater with a image buttons in the footer for paging. I also have linkbuttons in the header for sorting.The sorting works beautifully but the footer does not fire off the itemcommand event.
Expand|Select|Wrap|Line Numbers
  1. <FooterTemplate>
  2.   <tr>
  3.     <td align="left" class="footer" colspan="10">
  4.       &nbsp;
  5.       <pagerstyle cssclass="footer" font-italic="True" />
  6.       <pagertemplate></pagertemplate>
  7.       <asp:Label ID="PageLabel" runat="server" Text='<%# GetPagingInfo() %>' Visible="true"/>
  8.       &nbsp;
  9.       <asp:ImageButton ID="Page_First" runat="server" CommandArgument="First" CommandName="Page" ImageUrl="~/images/first_page.gif" ToolTip="Back to First Page" />
  10.       <asp:ImageButton ID="Page_Prev" runat="server" CommandArgument="Prev" CommandName="Page" ImageUrl="~/images/prev_page.gif" ToolTip="Back One Page" />
  11.       <asp:ImageButton ID="Page_Next" runat="server" CommandArgument="Next" CommandName="Page" ImageUrl="~/images/next_page.gif" ToolTip="Forward One Page" />
  12.       <asp:ImageButton ID="Page_Last" runat="server" CommandArgument="Last" CommandName="Page" ImageUrl="~/images/last_page.gif" ToolTip="Forward to Last Page" />
  13.       &nbsp;
  14.       <asp:ImageButton ID="PrintAllImageButton" runat="server" CommandName="PrintAll" ImageUrl="~/images/printer.gif" ToolTip="Print all pages" Width="20px" />
  15.     </td>
  16.   </tr>
  17. </FooterTemplate>

The cod ebehind in the page_Load is
Expand|Select|Wrap|Line Numbers
  1.  ar = new Pecos.AuditReview();
  2.         if (!IsPostBack)
  3.         {
  4.             //ViewState["sortdir"] = "desc";
  5.             ViewState["page"] = "1";
  6.             StartAt = 1;
  7.             dtefrom.MaxDate = DateTime.Now;
  8.             dtefrom.MinDate = DateTime.Now.AddYears(-1);
  9.             dtethru.MaxDate = DateTime.Now;
  10.             dtethru.MinDate = DateTime.Now.AddYears(-1);
  11.             dtefrom.SelectedDate = DateTime.Now.AddDays(-1);
  12.             dtethru.SelectedDate = DateTime.Now;
  13.             TableName = String.Empty;
  14.         }
  15.  
  16.             if(ddlTablenames.SelectedIndex<=0) LoadTableNames();
  17.        PageSize = Int32.Parse(Master.Pecos.Preferences["Default.PageSize"].ToString());
  18.         ddlRecordIds.Visible = ddlTablenames.SelectedIndex>0?true:false;
  19.  
  20.         FromDate = dtefrom.SelectedDate.ToShortDateString();
  21.         ToDate = dtethru.SelectedDate.ToShortDateString();
  22.         Action = "sel";
  23.      rptAuditActionsInformation.DataSource = ar.GetAuditRecordsCommand();
  24.         rptAuditActionsInformation.DataBind();
  25.         this.rptAuditActionsInformation.ItemCommand += new System.Web.UI.WebControls.RepeaterCommandEventHandler(this.rptAuditActionsInformation_ItemCommand);
Oct 13 '10 #1
4 3998
Frinavale
9,735 Expert Mod 8TB
You are performing a DataBind on your rptAuditActionsInformation in the Page Load event every time the page is loaded. This could be the problem.

Try moving this code to the Page PreRender event instead.

-Frinny
Oct 14 '10 #2
I moved the datasource and databind methods to the preender event but the itemcommand still doesn't fire for the footer. The thing which confuses me is the sort fires every time from the header template btu not the footer. I use very similar code in another page which does work. I can't see what's different.
Oct 14 '10 #3
Frinavale
9,735 Expert Mod 8TB
I'm not sure why you are having so many problems. I created a test project based on your footer and had no problems with this.

This is the ASPX page code that I used:
Expand|Select|Wrap|Line Numbers
  1. <div style="width:50%; margin:0 auto;">
  2.   <asp:Repeater ID="rptAuditActionsInformation" runat="server">
  3.     <HeaderTemplate>
  4.         <pagertemplate></pagertemplate>
  5.         <asp:LinkButton ID="Header_Page_First" runat="server" CommandArgument="First" CommandName="Page" Text="First Page" ToolTip="First Page" /> |
  6.         <asp:LinkButton ID="Header_Page_Prev" runat="server" CommandArgument="Prev" CommandName="Page" Text="Back" ToolTip="Back" /> | 
  7.         <asp:LinkButton ID="Header_Page_Next" runat="server" CommandArgument="Next" CommandName="Page" Text="Forward" ToolTip="Forward" /> | 
  8.         <asp:LinkButton ID="Header_Page_Last" runat="server" CommandArgument="Last" CommandName="Page" Text="Last Page" ToolTip="Last Page" /> |
  9.         <asp:LinkButton ID="Header_PrintAllLinkButton" runat="server" CommandName="PrintAll" Text="Print" ToolTip="Print" Width="20px" />
  10.     </HeaderTemplate>
  11.     <ItemTemplate>
  12.         <div style="margin:2px; border-bottom:solid 1px black">
  13.             <div>
  14.                 <asp:Localize ID="IDPrompt" runat="server" Text="ID: "> </asp:Localize>
  15.                 <asp:Localize ID="ID" runat="server" Text='<%# Eval("ID") %>' ></asp:Localize>
  16.             </div>
  17.             <div>
  18.                 <asp:Localize ID="NamePrompt" runat="server" Text="Name: "> </asp:Localize>
  19.                 <asp:Localize ID="Name" runat="server" Text='<%# Eval("Name") %>'></asp:Localize>
  20.             </div>
  21.         </div>
  22.     </ItemTemplate>
  23.     <FooterTemplate>
  24.         <pagerstyle cssclass="footer" font-italic="True" />
  25.         <pagertemplate></pagertemplate>
  26.         <asp:LinkButton ID="Page_First" runat="server" CommandArgument="First" CommandName="Page" Text="First Page" ToolTip="First Page" /> |
  27.         <asp:LinkButton ID="Page_Prev" runat="server" CommandArgument="Prev" CommandName="Page" Text="Back" ToolTip="Back" /> | 
  28.         <asp:LinkButton ID="Page_Next" runat="server" CommandArgument="Next" CommandName="Page" Text="Forward" ToolTip="Forward" /> | 
  29.         <asp:LinkButton ID="Page_Last" runat="server" CommandArgument="Last" CommandName="Page" Text="Last Page" ToolTip="Last Page" /> |
  30.         <asp:LinkButton ID="PrintAllLinkButton" runat="server" CommandName="PrintAll" Text="Print" ToolTip="Print" Width="20px" />
  31.     </FooterTemplate>
  32.   </asp:Repeater>
  33. </div>


This is the VB.NET code for the page:
Expand|Select|Wrap|Line Numbers
  1. Private pagedData As PagedDataSource 'Aids with paging the data displayed in the Repeater
  2. Private characters As List(Of DisneyCharacter) 'Used as the data source displayed in the Repeater
  3.  
  4. 'Names of Disney Characters used to create the data source for the Repeater
  5. Private characterNames() As String = {"Mickey Mouse", "Mini Mouse", "Pluto", "Goofy", "Donald Duck", "Daisy Duck", "Chip", "Dale", _
  6.                             "Abby Mallard", "Abigail Gabble", "Abis Mal", "Abu", "Adella", "The Agent", "Agent Wendy Pleakley", "Akela", "Al the Alligator", "Aladar", "Aladdin", "Alameda Slim ", "Alan-a-Dale", _
  7.                             "Alana", "Jennifer Hale", "Alcmene", "Alice", "Amelia Gabble", "Amos Slade", "Amphitryon", "Anastasia Tremaine", "Anda", "Andrina", _
  8.                             "Cadpig", "Calliope Lillias", "Captain Amelia", "Captain Gantu", "Captain James Hook", "Carl the Robot", "Carlotta the Maid", "Cassim"}
  9.  
  10.  
  11. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  12.     'Initializing data source for the Repeater
  13.     InitializeRepeaterDataSource()
  14. End Sub
  15.  
  16. Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
  17.     'Setting the data source for the Repeater and binding it to the data
  18.     rptAuditActionsInformation.DataSource = pagedData
  19.     rptAuditActionsInformation.DataBind()
  20. End Sub
  21.  
  22. Private Sub rptAuditActionsInformation_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles rptAuditActionsInformation.ItemCommand
  23.  
  24.     'Handling the paging action that the user performed using the controls in the footer.
  25.     Select Case e.CommandArgument
  26.         Case "First"
  27.             pagedData.CurrentPageIndex = 0
  28.         Case "Prev"
  29.             If pagedData.CurrentPageIndex > 0 Then
  30.                 pagedData.CurrentPageIndex = pagedData.CurrentPageIndex - 1
  31.             End If
  32.         Case "Next"
  33.             If pagedData.CurrentPageIndex < pagedData.PageCount - 1 Then
  34.                 pagedData.CurrentPageIndex = pagedData.CurrentPageIndex + 1
  35.             End If
  36.         Case "Last"
  37.             pagedData.CurrentPageIndex = pagedData.PageCount - 1
  38.     End Select
  39.  
  40.     'Storing the current page index in ViewState so that we can retrieve 
  41.     'this information the next time the page is loaded to set the PagedDataSource control
  42.     ViewState("currentPage") = pagedData.CurrentPageIndex
  43. End Sub
  44.  
  45. Private Sub InitializeRepeaterDataSource()
  46.  
  47.     'Retrieving the list of characters from Session
  48.     characters = CType(Session("characters"), List(Of DisneyCharacter))
  49.  
  50.     'If the list doesn't exist in Session, creating it and storing it in Session for next time
  51.     If characters Is Nothing Then
  52.         characters = New List(Of DisneyCharacter)
  53.         For i As Integer = 0 To characterNames.Length - 1
  54.             characters.Add(New DisneyCharacter(i * 111, characterNames(i)))
  55.         Next
  56.         Session("characters") = characters
  57.     End If
  58.  
  59.     'Initializing the PagedDataSource which aids with paging the data in the Repeater
  60.     pagedData = New PagedDataSource
  61.  
  62.     'Setting the data source for the PagedDataSource to the data
  63.     pagedData.DataSource = characters
  64.  
  65.     'Setting the number of items to display in a page
  66.     pagedData.PageSize = 5
  67.  
  68.     'Specifying that the control should allow paging to take place
  69.     pagedData.AllowPaging = True
  70.  
  71.     'Setting the current page index to that which is stored in ViewState (if there is nothing in ViewState then it is 0)
  72.     pagedData.CurrentPageIndex = CType(ViewState("currentPage"), Integer)
  73. End Sub
  74.  
  75.  
  76. ''' <summary>
  77. ''' This class is used as data for the repeater
  78. ''' </summary>
  79. ''' <remarks></remarks>
  80. Private Class DisneyCharacter
  81.     Private _id As Integer
  82.     Private _name As String
  83.     Public Property ID As Integer
  84.         Get
  85.             Return _id
  86.         End Get
  87.         Set(ByVal value As Integer)
  88.             _id = value
  89.         End Set
  90.     End Property
  91.     Public Property Name As String
  92.         Get
  93.             Return _name
  94.         End Get
  95.         Set(ByVal value As String)
  96.             _name = value
  97.         End Set
  98.     End Property
  99.     Public Sub New(ByVal id As Integer, ByVal name As String)
  100.         Me.ID = id
  101.         Me.Name = name
  102.     End Sub
  103. End Class
Everything works fine....give it a try if you want :)

-Frinny
Oct 15 '10 #4
Very simple solution, take the code outside of the repeater's footer, and use it outside of the repeater entirely. In fact, if you have an event to use, like a button click, simply never use it in the footer, problem solved.
Oct 30 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Andrés Giraldo | last post by:
Hi! I'm adding an asp button to a datagrid on the ItemDataBound event, when the user clicks on this button, I basically remove the button and create other 2 buttons... my problem is.. the 2 last...
3
by: sonu | last post by:
I have created a window application which has two grid we drag and drop from one grid to other. tn i changed that window application into DLL. and called that dll in a web page. grid are...
0
by: Cold Nuke | last post by:
Hi all, |-------------| changeSpeed |----------|simulate |-------------| |simulation |------------->|Controller|--------->|Simulation | |controlPanel | |Loop |second ...
2
by: Stan | last post by:
I cannot make the link buttons fire ItemCommand from repeater control. Here is the code: <asp:repeater id=rptLetters runat="server"> <itemtemplate> <asp:linkbutton id="lnkLetter"...
4
by: James Hancock | last post by:
I have a page, which is inherited from another page (PageEx is what I call it) All of our pages are based on PageEx because there is a bunch of logic stuff we do in there. My problem is, that if...
3
by: sri_san | last post by:
Hello Group, I use a datagrid with a linkbutton to delete the selected row. Added javascript confirm dialogue box in itembound event. The itemCommand event does not seem to fire when I debug the...
0
by: jonathan.beckett | last post by:
I have been working on a client project recently that is using winforms ..NET user controls within web pages in Internet Explorer, and need to find out how to make the user control communicate back...
9
by: BartMan | last post by:
Greetings, I am trying to fire aysnc events in c++/clr, and I can't seem to get it to work. It seems to work fine in c#, but when I try c++/clr, I can't seem to get it to compile in the c++/clr...
1
by: rajkumarbathula | last post by:
Hi I am struckup with a big issue. ie., On my Page i am rendering 2 dynamic datalists each has dynamic link buttons. my problem is: i am not able to handle ItemCommandEvent of both the...
0
by: siva prasanth | last post by:
Hi all I am using C# to create add-ins But events are not firing in citrix environment can u suggest solution Thanks in advance siva
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.