Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

Highlight datagrid row client side

  Asked By: Pamela    Date: Sep 16    Category: Asp.net    Views: 1172

I have a simple datagrid with a checkbox. I want to highlight the
row with the onclick of the checkbox. I've tried various javascript
in my aspx file and tried adding an onclick attribute to the
checkbox in the datagrid once I populate the datagrid, but nothing
fires. Do I need to move the firing of the javascript to the
edititem...or somewhere else?

Help is appreciated as this is driving me nuts!

Also, what parts of the datagrid are the <tr> and <td> tags? The
ItemTemplate columns? Am I just off with this question?



1 Answer Found

Answer #1    Answered By: Clayton Richardson     Answered On: Sep 16

Client side  JS:

function setRowColor()
rowId = parseInt(frmMain.all["rowIndex"].value);
if ((rowId != -1) && (window.document.all[rowId].tagName == "TR"))
//window.document.all[rowId].style.backgroundColor = "yellow";
window.document.all[rowId].cells[0].style.backgroundColor = "yellow";
window.document.all[rowId].cells[1].style.backgroundColor = "yellow";

<body MS_POSITIONING="GridLayout" onload="setRowColor()"
bgcolor="ActiveBorder" scroll="no" leftmargin="10" topmargin="0"
rightmargin="10" bottommargin="0">

In code behind do something like:

if post back
string rowSourceIndex = Request["rowIndex"];
if (itemClicked != "")
Page.RegisterHiddenField("rowIndex", rowSourceIndex);


Page.RegisterHiddenField("rowIndex", "-1");

Email me off list if you have trouble with the above code.

Didn't find what you were looking for? Find more on Highlight datagrid row client side Or get search suggestion and latest updates.