By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,968 Members | 1,589 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,968 IT Pros & Developers. It's quick & easy.

LinkButton in Repeater: CommandArgument does not change value

P: 2
hi. im new here and new in web programming. i was trying to put a pagination for my table, it is working fine but i wanted to change the color of the current page. i found some solution but most of them are in c# and im using vb, im not sure if my codes are correct and thus, im having problem with the commandArgument value. Im always getting "1" eventhough i already click page 2, the result Page 1 always has the properties changed. Please help. thank you in advance. By the way im using an arraylist which is bound to repeater with linkbutton.

Expand|Select|Wrap|Line Numbers
  1. <asp:Repeater ID="rptPages" runat="server">
  2.             <HeaderTemplate>
  3.                 <div style="float: left">Page&nbsp</div>
  4.             </HeaderTemplate>
  5.             <ItemTemplate>
  6.                 <a style="float: left">
  7.                     <asp:LinkButton ID="btnPage" runat="server"
  8.                         CommandName="Page" CommandArgument="<%# Container.DataItem%>">
  9.                         &nbsp<%# Container.DataItem%></asp:LinkButton>
  10.                 </a>
  11.             </ItemTemplate>
  12.         </asp:Repeater>
  14. Protected Sub rptPages_ItemDataBound(sender As Object, e As RepeaterItemEventArgs) Handles rptPages.ItemDataBound
  16.         Dim lnkPage As LinkButton
  17.         Dim strPage As Integer
  18.         strPage = PageNumber + 1
  19.         If e.Item.ItemType = ListItemType.Item Then
  20.             lnkPage = e.Item.FindControl("btnPage")
  21.             If lnkPage.CommandArgument.ToString() = strPage.ToString() Then
  22.                 lnkPage.Enabled = False
  23.                 lnkPage.ForeColor = Drawing.Color.Black
  24.             End If
  25.         End If
  27.     End Sub
May 9 '14 #1
Share this Question
Share on Google+
1 Reply

P: 2
I've fixed it. I also have to allow alternatingitem, its where the other value is. the code should be like this,

Expand|Select|Wrap|Line Numbers
  1. If (e.Item.ItemType = ListItemType.Item) Or (e.Item.ItemType = ListItemType.AlternatingItem) Then
  2.             lnkPage = e.Item.FindControl("btnPage")
  3.             If lnkPage.CommandArgument.ToString() = strPage.ToString() Then
  4.                 lnkPage.Enabled = False
  5.                 lnkPage.ForeColor = Drawing.Color.Black
  6.             End If
  7.         End If
May 9 '14 #2

Post your reply

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