How do I change the background color of a dynamic linkbutton inside of a repeater?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • michaelmaria313
    New Member
    • Mar 2010
    • 1

    How do I change the background color of a dynamic linkbutton inside of a repeater?

    Hi All,

    I am brand new (like 2 weeks) to ASP.NET and VB.
    I have a series of linkbuttons that are generated dynamically inside a repeater.
    I need the background color of the selected linkButton to change and remain a new color when clicked. I thought that the ItemCommand property of the repeater would do the trick, but it doesn't.

    Here is the code for the repeater:

    Code:
        <asp:Repeater ID="rptModuleMenuList" runat="server" DataSourceID="srcModuleItemList" OnItemCommand="rptModuleMenuList_ItemCommand" OnItemDataBound="rptModuleMenuList_DataBound">
            <HeaderTemplate>
                <div class="moduleMenuClass">
            </HeaderTemplate>
            <ItemTemplate>
                    <asp:LinkButton runat="server" ID="modMenuButton1" CommandName="loadSubMenu" CommandArgument='<%#Eval("menu_item_id") %>' CssClass="taskMan"><%#Eval("menu_item_name") %></asp:LinkButton>
            </ItemTemplate>
            <FooterTemplate>
                </div>
            </FooterTemplate>
        </asp:Repeater>
    Here is the Code Behind:


    Code:
        Protected Sub rptModuleMenuList_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles rptModuleMenuList.ItemCommand
               Dim myButton As LinkButton
               myButton = Me.FindControl(e.Item.ClientID.ToString())
               myButton.BackColor = Drawing.Color.DimGray
        End Sub

    I have been hunting, reading, and reworking for a couple of hours now and I am completely confused. Any help would be greatly appreciated. Thanks!

    Mike
    Last edited by tlhintoq; Mar 2 '10, 06:36 PM. Reason: [CODE] ...Your code goes between code tags [/CODE]
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      I think that your CssClass for your LinkButton is overwriting what you are changing in code. Try changing the CssClass instead of setting the ForeColor.

      -Frinny

      Comment

      Working...