I am just want to check for empty text boxes and change the text the boxes if they are null in RowEditing event. I just can’t figure this out. Of course the some of the boxes will be empty when the Grid is populated. The other question is am I placing this in the right event?
Here is the row editing event :
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
fill_grid();
//Set the edit index.
GridView1.EditIndex = e.NewEditIndex;
//Bind data to the GridView control.
check_grid_boxes();
GridView1.DataBind();
}
Here is the check_grid_boxes Method :
protected void check_grid_boxes()
{
if (gtxtLane.Text == "")
{
gtxtLane.Text = "0";
}
else if (gtxtCarriers.Text == "")
{
gtxtCarriers.Text = "0";
}
else if (gtxtREV.Text == "")
{
gtxtREV.Text = "0";
}
return;
}
Before you mention Java Script or Jquery. This is a web control and my attempts at using java has not worked.
I changed my code to this :
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
fill_grid();
GridView1.EditIndex = e.NewEditIndex;
var lane = (TextBox)GridView1.Rows[e.NewEditIndex].FindControl("gtxtLane");
var car = (TextBox)GridView1.Rows[e.NewEditIndex].FindControl("gtxtCarriers");
var badcar = (TextBox)GridView1.Rows[e.NewEditIndex].FindControl("gtxtBadCarriers");
if (String.IsNullOrEmpty(lane.Text))
{
lane.Text = "0";
}
else if (String.IsNullOrEmpty(badcar.Text))
{
badcar.Text = "0";
}
else if (String.IsNullOrEmpty(car.Text))
{
car.Text = "0";
}
GridView1.DataBind();
}
DUH!!!! how bout –> select isnull(lane,’0′) as Lane <—. I can’t believe I didn’t think of that!! 6 hours wasted!!