开发者

Find a GridView row programmatically

The row has a LinkButton that when clicked needs to highlight the row.

Code so far:

protected void linkbutton1_Click(object sender, EventArgs e)
{
    LinkButton l = (LinkButton)sender;
    GridViewRow g = (GridViewRow)l.Parent; // what is the correct way to do this?
    //g.Style etc etc
}
开发者_Go百科


first of all set the "CommandName" property of LinkButton to "select", then in the selectedIndexChanging event of gridview write below code:

for (int i = 0; i < GridView1.Rows.Count;i++ )
            GridView1.Rows[i].BackColor = System.Drawing.Color.White;
 GridView1.Rows[e.NewSelectedIndex].BackColor = System.Drawing.Color.Cornsilk;


Make use of the RowCommand event of the GridView instead of the Click event of the LinkButton.

Then you can have a CommandName on the LinkButton such as "HighlightRow" and do something like the following:

Select Case e.CommandName
  Case "HighlightRow"
    e.item.row.attributes("class") = "highlight"
End Select

Sorry its in VB.NET and not C#


1.) Set Command Name Property to "Select"

2.) Change style either on code behind as shown by @Raymond or give set Cssclass attribute for SelectedRowStyle of gridview to CssClass="selecterowstyle"

.selectedRowstyle { background-color:#EAEAEA; }

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜