Highlighting row in Gridview?

V

VMI

How can I select a row in a Web gridview? I added a ButtonField to my
gridview, but I'm not certain what other properties I should change in
order for the row to be highlighted. I also changed the
EditRowStyle.BackColor and EditRowStyle.BorderColor properties so that
I could see some change when I click on the button column. When I
click on the button, it does postback, but I don't see the highlighted
item.
What am I doing wrong? I'm filling the datagrid in the (!IsPostBack)
condition.

Thanks.
 
M

Mark Rae

How can I select a row in a Web gridview? I added a ButtonField to my
gridview, but I'm not certain what other properties I should change in
order for the row to be highlighted. I also changed the
EditRowStyle.BackColor and EditRowStyle.BorderColor properties so that
I could see some change when I click on the button column. When I
click on the button, it does postback, but I don't see the highlighted
item.
What am I doing wrong? I'm filling the datagrid in the (!IsPostBack)
condition.

Not sure exactly what you're trying to achieve here, but the following code
might help. Basically, you click on a row on the GridView, and it takes you
to another page passing the row ID as a QueryString.

If you need to do other things e.g. just highlight the row which was
clicked, you just need the GridView's SelectedValue and from this you can
work out which row to change the BackColor for etc...


<asp:GridView ID="gvGrid" runat="server"
OnRowDataBound="gvGrid_RowDataBound"
OnSelectedIndexChanged="gvGrid_SelectedIndexChanged">
....
....
....
</asp:GridView>

protected void gvGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick",
ClientScript.GetPostBackEventReference(gvGrid, "Select$" +
e.Row.RowIndex.ToString()));
}
}

protected void gvGrid_SelectedIndexChanged(object sender, EventArgs e)
{
string strRecordID = gvGrid.SelectedValue.ToString();
Response.Redirect("edit.aspx?id=" + strRecordID, false);
}
 
V

VMI

Thanks for the post.

The reason i was asking is that in another web app I'm working on, the
programmer who worked on this did the same thing by (apparently) just
adding "<SelectedItemStyle BackColor="lime"></SelectedItemStyle>" to
the html. He did this with a datagrid in .net 2003 v1.1. Basically
what I want to do is highlight the row whose "ButtonColumn" I clicked
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top