c# - Add and remove CssClass ASP.NET -
i have weird behavior asp.net application. want change color of current selected row in grid view.
my gridview defined :
<asp:gridview [..] onselectedindexchanged="supresultlist_selectedindexchanged"> [..] <rowstyle cssclass="datagriditem" /> <alternatingrowstyle cssclass="datagridalternateitem" /> </asp:gridview>
in code-behind, have :
protected void supresultlist_selectedindexchanged(object sender, eventargs e) { gridview grid = sender gridview; // remove class "selected" older row foreach (gridviewrow row in grid.rows) { row.cssclass = row.cssclass.replace("adminrowselected", string.empty); } grid.selectedrow.cssclass = string.join(" ", grid.selectedrow.cssclass, "adminrowselected"); }
may there better way want ?
anyway, when gridview first rendered, rows have classes. when select row , enter in supresultlist_selectedindexchanged, row.cssclass empty (so result of row.cssclass.replace("adminrowselected", string.empty) "" , string.join(" ", grid.selectedrow.cssclass, "adminrowselected"); "adminrowselected"). after processing lose original class , rows become white (except selected row).
i tried instead of loop failed :
grid.rowstyle.cssclass = "datagriditem"; grid.alternatingrowstyle.cssclass = "datagridalternateitem";
do have idea of happening (and how correct ^^) ?
thanks in advance !
have tried selectedrowstyle
?
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.selectedrowstyle.aspx
Comments
Post a Comment