我只想检查空文本框并更改文本框,如果它们在 RowEditing 事件中为空。我就是想不通。当然,当填充网格时,某些框将是空的。另一个问题是我把它放在正确的事件中吗?
这是行编辑事件:
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();
}
这是 check_grid_boxes 方法:
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;
}
在您提到 Java Script 或 Jquery 之前。这是一个 Web 控件,我尝试使用 java 没有奏效。
我将代码更改为:
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();
}