Selecting the DataGrid Row
Hi,
Does anyone know how to select an entire row in a datagrid?
For example if I click one cell it's enitre row is higlighted.
Thank you.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
libertychisasuroPosted Apr 3, 2005, 10:15 PM
gjmproposalPosted Mar 29, 2005, 6:25 PM
this.grd.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.grd_ItemDataBound);Add code to add javascript events to each rowprivate void grd_ItemDataBound(object sender, DataGridItemEventArgs e) { if(e.Item.ItemIndex >= 0) { e.Item.Attributes.Add("onmouseover","setStyleOn(this)"); e.Item.Attributes.Add("onmouseout","setStyleOff(this)"); e.Item.Attributes.Add("onclick","handleClick(this)"); } }Add javascript code to you aspx page set the style of the rowsfunction setStyleOn(elem) { elem.className = "rowon"; } function setStyleOff(elem) { elem.className = "rowoff"; } function handleClick(elem) { //do something setStyleOn(elem); }