asp.net - Change row color of gridview by database Values -


i making application in asp.net shows values in gridview database.in database having colmn named statusid has value of 1 or 2 or 3.

i tried show grid view rows in different color statusid values. never works. how can in asp.net.

here code

protected void gridview1_rowdatabound(object sender, gridviewroweventargs e)     {          connection.open();         sqlcommand command1 = connection.createcommand();         command1.commandtext = "select statuscolor status statusid=(select statusid fileinfo userid=(select userid userinfo email='" + session["email"].tostring() + "'))";          (int = 0; < gridview1.rows.count; i++)         {             using (sqldatareader reader = command1.executereader())             {                 while (reader.read())                 {                     statusid = reader["statuscolor"].tostring();                 }              gridview1.rowstyle.backcolor = color.fromname(statusid);                    }          }           foreach (gridviewrow row in gridview1.rows)         {             row.backcolor = color.green;         }         sqlcommand com = new sqlcommand("gridcolor", connection);         com.commandtype = commandtype.storedprocedure;         com.parameters.addwithvalue("@statusid", statusid);         com.parameters.add("@statuscolor", sqldbtype.nvarchar, 30);         com.parameters["@statuscolor"].direction = parameterdirection.output;         com.executenonquery();         string msg = (string)com.parameters["@statuscolor"].value;         connection.close();     }  

what mistake doing here?

edit

i have color codes stored in database named statuscolor. have apply color these status.

you have statusid having values 1,2,3 , passing color.fromname , 1,2,3 not names of color can use switch assign different colors based on statusid .

color rowcolor = color.red;     switch(statusid) {     case 1:          rowcolor = color.green;          break;      case 2:          rowcolor = color.white;          break;     case 3:          rowcolor = color.blue;          break; }    gridview1.rowstyle.backcolor = rowcolor ;  

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -