空のテキスト ボックスをチェックし、RowEditing イベントで null の場合はテキストをボックスに変更したいだけです。私はこれを理解することはできません。もちろん、グリッドにデータが入力されると、一部のボックスは空になります。もう 1 つの質問は、これを適切なイベントに配置しているかどうかです。
行編集イベントは次のとおりです。
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();
}