我想在我編輯一些信息時對Gridview進行驗證,但我不知道如何。我不使用簡單的方法,我的代碼(C#)做這件事,我不知道如何在我的文本框添加驗證...驗證GridView_RowUpdating textfields ASP.NET
下面是我的一些代碼:
protected void gvAdmins_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
DataTable dt = (DataTable)Session["TaskTableA"];
GridViewRow row = gvAdmins.Rows[e.RowIndex];
dt.Rows[row.DataItemIndex]["ID"] = ((TextBox)(row.Cells[1].Controls[0])).Text;
dt.Rows[row.DataItemIndex]["H:"] = ((TextBox)(row.Cells[4].Controls[0])).Text;
dt.Rows[row.DataItemIndex]["M:"] = ((TextBox)(row.Cells[5].Controls[0])).Text;
dt.Rows[row.DataItemIndex][6] = ((TextBox)(row.Cells[7].Controls[0])).Text;
dt.Rows[row.DataItemIndex][7] = ((TextBox)(row.Cells[8].Controls[0])).Text;
dt.Rows[row.DataItemIndex][8] = ((TextBox)(row.Cells[9].Controls[0])).Text;
dt.Rows[row.DataItemIndex][9] = ((TextBox)(row.Cells[10].Controls[0])).Text;
dt.Rows[row.DataItemIndex][10] = ((TextBox)(row.Cells[11].Controls[0])).Text;
gvAdmins.EditIndex = -1;
int id = Convert.ToInt32(Request.QueryString["id"]);
string idCar = ((TextBox)(row.Cells[1].Controls[0])).Text;
int hom = Convert.ToInt32(((TextBox)(row.Cells[4].Controls[0])).Text);
int mu = Convert.ToInt32(((TextBox)(row.Cells[5].Controls[0])).Text);
int t1 = 0;
int t2 = 0;
int t3 = 0;
int t4 = 0;
int t5 = 0;
t1 = Convert.ToInt32(((TextBox)(row.Cells[7].Controls[0])).Text);
t2 = Convert.ToInt32(((TextBox)(row.Cells[8].Controls[0])).Text);
t3 = Convert.ToInt32(((TextBox)(row.Cells[9].Controls[0])).Text);
t4 = Convert.ToInt32(((TextBox)(row.Cells[10].Controls[0])).Text);
t5 = Convert.ToInt32(((TextBox)(row.Cells[11].Controls[0])).Text);
int total = hom + mu;
int totalT = t1 + t2 + t3 + t4 + t5;
string comandoIF = //MY SQL Command;
conn.IAE(comandoIF);
dt.Rows[row.DataItemIndex]["Total:"] = total.ToString();
BindDataA();
}
我希望你能幫助我,謝謝。
好吧,我問別人,他告訴我,我可以使用腳本和CSS類把文本框的類型到數量,所以我沒有...這有點爲我工作,謝謝 – OPMUANRK
沒錯,那也可以。但請記住,舊版瀏覽器不會重構這些屬性並顯示正常的文本框。 – VDWWD