This is a migrated thread and some comments may be shown as answers.

Highlight Row on linkbutton press

3 Answers 163 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vijaianand
Top achievements
Rank 1
Vijaianand asked on 11 Jan 2012, 03:25 PM
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

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 12 Jan 2012, 06:39 AM
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
0
Vijaianand
Top achievements
Rank 1
answered on 16 Jan 2012, 04:50 PM
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
0
Jayesh Goyani
Top achievements
Rank 2
answered on 16 Jan 2012, 06:06 PM
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
Tags
Grid
Asked by
Vijaianand
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Vijaianand
Top achievements
Rank 1
Share this question
or