Set selectedindex in gridview with jQuery
In my gridview rowdatabound event, I've added a bit of code to set the selectedindex of my gridview as follows :-
e.Row.Attributes.Add("onclick", ClientScript.GetPostBackEventReference(myGridView, "Select$" + e.Row.RowIndex.ToString()));
it works fine except that I also have change events bound for each of my columns in the gridview and they won't fire because of the above. I want to move the above into my change event so that it would set the selected index for the gridview as well as do other stuff in my change event.
Below is the binding for the checkbox column in the gridview.
var coDeletedFlagCol = $(".myGridViewCol5");
var coRowDirty = $(".myGridViewCol6");
for (var i = 0; i < coDeletedFlagCol.length; i++) {
var eventData = {
index: i
};
$(coDeletedFlagCol[i]).bind("change", eventData, setDirtyRow);
};
function setDirtyRow(event) {
var _idx = event.data.index;
var _id = $(".myGridViewCol6").eq(_idx);
_id.val("Y");
}
My checkbox "coDeletedFlagCol" has a cssclass="myGridViewCol5" and there is a hidden field "coRowDirty" for the DirtyRow indicator which has a cssclass="myGridViewCol6".
In the setDirtyRow function, I want to add the bit of code that would set my gridview's selected index to the index of the current changed row.
Can someone please help ? Thanks in advance.