LinkButton in Repeater: CommandArgument does not change value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • klsantos
    New Member
    • May 2014
    • 2

    LinkButton in Repeater: CommandArgument does not change value

    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.

    Code:
    <asp:Repeater ID="rptPages" runat="server">
                <HeaderTemplate>
                    <div style="float: left">Page&nbsp</div>
                </HeaderTemplate>
                <ItemTemplate>
                    <a style="float: left">
                        <asp:LinkButton ID="btnPage" runat="server"
                            CommandName="Page" CommandArgument="<%# Container.DataItem%>">
                            &nbsp<%# Container.DataItem%></asp:LinkButton>
                    </a>
                </ItemTemplate>
            </asp:Repeater>
    
    Protected Sub rptPages_ItemDataBound(sender As Object, e As RepeaterItemEventArgs) Handles rptPages.ItemDataBound
    
            Dim lnkPage As LinkButton
            Dim strPage As Integer
            strPage = PageNumber + 1
            If e.Item.ItemType = ListItemType.Item Then
                lnkPage = e.Item.FindControl("btnPage")
                If lnkPage.CommandArgument.ToString() = strPage.ToString() Then
                    lnkPage.Enabled = False
                    lnkPage.ForeColor = Drawing.Color.Black
                End If
            End If
    
        End Sub
    Last edited by klsantos; May 9 '14, 05:41 PM. Reason: additional info
  • klsantos
    New Member
    • May 2014
    • 2

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

    Code:
    If (e.Item.ItemType = ListItemType.Item) Or (e.Item.ItemType = ListItemType.AlternatingItem) Then
                lnkPage = e.Item.FindControl("btnPage")
                If lnkPage.CommandArgument.ToString() = strPage.ToString() Then
                    lnkPage.Enabled = False
                    lnkPage.ForeColor = Drawing.Color.Black
                End If
            End If

    Comment

    Working...