"VMI" <my****@excite.comwrote in message
news:11*********************@i3g2000cwc.googlegrou ps.com...
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_SelectedIndexChange d">
....
....
....
</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);
}