Highlight Row on linkbutton press

4 posts, 0 answers
  1. Vijaianand
    Vijaianand avatar
    82 posts
    Member since:
    Jul 2012

    Posted 11 Jan 2012 Link to this post

    Hi

    I have a linkbutton in the template column. I am already triggering an event on the link button press and able to get the row. I was able to highlight it but when the next row linkbutton is clicked, i need to put the previous selected to original position. I was trying to do using row id but there is no ID for row. How can I do it differently? I was also thought may be I can put arrow in the gridgroupsplittercolumn for row selected but I don't know how to get splittercolumn id for the selected row.

    Any suggestion would be appreciated.

    Vijai
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 12 Jan 2012 Link to this post

    Hello,


    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
                OnItemDataBound="RadGrid1_ItemDataBound" OnItemCommand="RadGrid1_ItemCommand">
                <MasterTableView DataKeyNames="ID,Name" CommandItemDisplay="Top">
                    <Columns>
                        <telerik:GridBoundColumn DataField="Name" HeaderText="Name">
                        </telerik:GridBoundColumn>
                        <telerik:GridTemplateColumn>
                            <ItemTemplate>
                              <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">Link</asp:LinkButton>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                    </Columns>
                </MasterTableView>
            </telerik:RadGrid>
    protected void LinkButton1_Click(object sender, EventArgs e)
       {
           GridDataItem item1 = ((sender as LinkButton).NamingContainer as GridDataItem);
     
           foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
           {
               item.BackColor = System.Drawing.Color.White; // set this color as per your skin
           }
     
           item1.BackColor = System.Drawing.Color.Red;
       }


    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Vijaianand
    Vijaianand avatar
    82 posts
    Member since:
    Jul 2012

    Posted 16 Jan 2012 Link to this post

    Jayesh,

    That will slow down the page if you have too many rows since you are going through each row to clear the backcolor.

    I have found different solution using DataKeyName. 
    Dim lnkRow As GridDataItem = CType(lnkbtn.NamingContainer, GridDataItem)
    If lnkRow IsNot Nothing Then
        If ViewState("PrevSkillID") IsNot Nothing Then
            If ViewState("PrevSkillID").ToString <> SkillId Then
                Dim prevrow As GridDataItem = CType(RadGrid1.MasterTableView.FindItemByKeyValue("SkillID", ViewState("PrevSkillID").ToString), GridDataItem)
                prevrow.BackColor = CType(ViewState("PrevlnkRowColor"), Drawing.Color)
            End If
        End If
        lnkRow.BackColor = Drawing.Color.LightGoldenrodYellow
        ViewState("PrevSkillID") = SkillId
        ViewState("PrevlnkRowcolor") = lnkRow.BackColor.ToString
    End If
  5. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 16 Jan 2012 Link to this post

    Hello,

    yes, i agree with you.
    if you set pagging then it will go throw only limited rows.

    let me know if you still have any issue.

    Thanks,
    Jayesh Goyani
Back to Top