Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

How to click/select Row in ASP.NET GridView or HTML Table

0.00/5 (No votes)
27 Jun 2012 1  
The above code will slow down the browser and the browser can hang when Rows in Grid will be 10000 or above.Please view the below suggestion:CS Codeprotected void grvGroups_RowDataBound(object sender, GridViewRowEventArgs e){ if (e.Row.RowType == DataControlRowType.DataRow) { ...

The above code will slow down the browser and the browser can hang when Rows in Grid will be 10000 or above. Please view the below suggestion:

CS Code

protected void grvGroups_RowDataBound(object sender, GridViewRowEventArgs e)
{
 if (e.Row.RowType == DataControlRowType.DataRow)
  {
    e.Row.Attributes.Add("onclick", "setGridValue('" + e.Row.ClientID + "')");
  }
}

HTML Code

.sel
{
     color: #303030;
     font-size:3em;
     font-weight:bold;
     cursor:default;
}
.desel
{
     color: #909090;
     font-size:2em;
     font-weight:normal;
     cursor:pointer;
}

 

var oldro;
function setGridValue(ro)
{
 var rs=document.getElementById(ro);
 if(oldro!=null)
 {
  if(rs.className=="sel")
   return;
  oldro.className="desel";
 }
 rs.className="sel";
 oldro=rs;
}

And forget then loop.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here