"VMI" <my****@excite. comwrote in message
news:11******** *************@i 3g2000cwc.googl egroups.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.Ba ckColor and EditRowStyle.Bo rderColor 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_RowData Bound"
OnSelectedIndex Changed="gvGrid _SelectedIndexC hanged">
....
....
....
</asp:GridView>
protected void gvGrid_RowDataB ound(object sender, GridViewRowEven tArgs e)
{
if (e.Row.RowType == DataControlRowT ype.DataRow)
{
e.Row.Attribute s.Add("onclick" ,
ClientScript.Ge tPostBackEventR eference(gvGrid , "Select$" +
e.Row.RowIndex. ToString()));
}
}
protected void gvGrid_Selected IndexChanged(ob ject sender, EventArgs e)
{
string strRecordID = gvGrid.Selected Value.ToString( );
Response.Redire ct("edit.aspx?i d=" + strRecordID, false);
}