toraj58
December 31st, 2008, 04:38 AM
i want when the user mouse over a row in a datagrid then the back ground color of the row to be changed to another color (without posting back the page)
|
Click to See Complete Forum and Search --> : [RESOLVED] change row color in datagrid(without post back) toraj58 December 31st, 2008, 04:38 AM i want when the user mouse over a row in a datagrid then the back ground color of the row to be changed to another color (without posting back the page) toraj58 December 31st, 2008, 12:35 PM i tried this code in the rowdatabound event: Color rowColor = e.Row.BackColor; string strColor = System.Drawing.ColorTranslator.ToHtml(rowColor); e.Row.Attributes.Add("onmouseover", "style.background = '#FFFFC0'; style.cursor='pointer'"); e.Row.Attributes.Add("onmouseout", "style.background = '#" + strColor + "'"); mouseover works fine but when i mouseout instead of changing the color back to previous row color it is always changing to white color. what is the problem? nabeelisnabeel January 1st, 2009, 02:21 AM Do the same thing you did in RowCreated event instead of RowDataBound event. And use 'style.background' instead of 'background'. Tell me what happens. toraj58 January 1st, 2009, 10:34 AM i did the same thing in RowCreated event the result is the same as doing it in the RowDataBound event. i already has used style.background. something that i have done easily in PHP wasted my time about 4 hours! toraj58 January 1st, 2009, 10:41 AM i examined the value of ColorTranslator.ToHtml and it was empty! string strColor = System.Drawing.ColorTranslator.ToHtml(rowColor); eclipsed4utoo January 1st, 2009, 11:07 AM does "rowColor" have a value? toraj58 January 1st, 2009, 11:30 AM i debugged the code and i placed a Break Point in this line: (Break Point) protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) when i reached the break point i added the properties that were suspecious to the add watch: BackColor, Attributes and CssStyle and several times i pressed F11 but all the time all of them were empty. also i examined several other properties changes in Locals window and Autos Window but i did not see any color change!!! it is weird....my row are colorfull...i have color for normal rows and another color for alternative rows but i didn't see any color changes or assigning during debug! toraj58 January 1st, 2009, 11:32 AM @eclipse4utoo: no, rowColor is empty all the time! nabeelisnabeel January 2nd, 2009, 07:41 AM try this in RowCreated event.. if (e.Row.RowType == DataControlRowType.DataRow) { // when mouse is over the row, save original color to new attribute, and change it to highlight yellow color e.Row.Attributes.Add("onmouseover","this.originalstyle=style.backgroundColor;this.style.backgroundColor='#CCDDFF'"); // when mouse leaves the row, change the bg color to its original value e.Row.Attributes.Add("onmouseout", "style.backgroundColor=this.originalstyle;"); } and tell me what happens. toraj58 January 3rd, 2009, 03:26 AM it was briliant....before i test it i got the idea from you and i was sure this time it will work. and it worked. thank you very much my friend. :thumb: codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |