我只是想檢查空的文本框,並更改文本框,如果他們在RowEditing事件中爲null。我無法弄清楚這一點。當網格填充時,一些框當然會是空的。另一個問題是我把這個放在正確的事件?空引用和if語句c#
這裏是行編輯事件:
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腳本或jQuery的。這是一個網頁控制,我嘗試使用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();
}
什麼行引發異常? –
我知道這聽起來很迂腐,但我認爲你的意思是JavaScript而不是Java。相似的名字,兩個完全不同的東西。 –
check_grid_boxes方法拋出異常。我正在想我如何關閉If語句只是使用返回是錯誤的? – briskovich