editing gridview problem with rowdatabound event

M

Mike P

I have a couple of columns in my gridview that I am adding formatting to
in the RowDataBound event. But when I want to edit the rows when the
RowDataBound event gets called, I get an error. I'm thinking that I
need some kind of statement where I check whether the grid is in editing
mode before I run the code. Here is my code :

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label ForecastType =
(Label)e.Row.FindControl("lblForecastType");

switch (ForecastType.Text)
{
case "Analysis":
e.Row.Cells[2].BackColor =
System.Drawing.Color.Cyan;
break;

case "Call Centre":
e.Row.Cells[2].BackColor =
System.Drawing.Color.Lime;
break;

case "Data":
e.Row.Cells[2].BackColor =
System.Drawing.Color.Yellow;
break;

case "Data/Analysis":
e.Row.Cells[2].BackColor =
System.Drawing.Color.Magenta;
break;
}

Label Probability =
(Label)e.Row.FindControl("lblProbability");

switch (Probability.Text)
{
case "0.25":
e.Row.Cells[4].Text = "A (25%)";
e.Row.Cells[4].BackColor =
System.Drawing.Color.Coral;
break;

case "0.5":
e.Row.Cells[4].Text = "B (50%)";
e.Row.Cells[4].BackColor =
System.Drawing.Color.OrangeRed;
break;

case "0.75":
e.Row.Cells[4].Text = "C (75%)";
e.Row.Cells[4].BackColor = System.Drawing.Color.Red;
break;

case "0.751":
e.Row.Cells[4].Text = "Proforma (75%)";
e.Row.Cells[4].BackColor =
System.Drawing.Color.Maroon;
break;

case "1":
e.Row.Cells[4].Text = "In (100%)";
e.Row.Cells[4].BackColor =
System.Drawing.Color.White;
break;
}

LinkButton EditButton =
(LinkButton)e.Row.Cells[8].Controls[0];
EditButton.ForeColor = System.Drawing.Color.Blue;

LinkButton DeleteButton =
(LinkButton)e.Row.FindControl("DeleteButton");
DeleteButton.Attributes.Add("onclick", "javascript:return "
+
"confirm('Are you sure you want to delete forecast number "
+
DataBinder.Eval(e.Row.DataItem, "ForecastKey") + "?')");

DeleteButton.ForeColor = System.Drawing.Color.Blue;
}
}

Any assistance would be really appreciated!


Cheers,

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top