我想实现的GridView中的复选框,GridView的复选框问题asp.net
此复选框的任务是验证记录,
当此验证按钮被按下,用检查所有项目复选框被输入到数据库中
这是我的代码:
protected void Button1_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox cbox = ((CheckBox)row.FindControl("Verify"));
if (cbox.Equals(true))
{
String DraftsText = ((TextBox)row.FindControl("numDrafts")).Text;
String TCtext = ((TextBox)row.FindControl("numTC")).Text;
if (row.RowType == DataControlRowType.DataRow)
{
//Header trs = new Header();
// GridView1.Rows[0].FindControl("numTC");
if (TCtext != "" && DraftsText != "")
{
// try
// {
string date = row.Cells[4].Text;
DateTime dateTime = Convert.ToDateTime(date);
string dateFormatted = dateTime.ToString("d-MMM-yy");
string unit = row.Cells[5].Text;
string currency = row.Cells[6].Text;
string totalFC = row.Cells[7].Text;
string totalDC = row.Cells[8].Text;
int d = Convert.ToInt32(DraftsText);
int tc = Convert.ToInt32(TCtext);
hdr = new Header(d, tc, dateFormatted, unit, currency, totalFC, totalDC);
hdr.InsertFCTC(hdr);
}
}
}
}
}
我可能会在这个错误的方式,但在如果(cbox.Equals(真))可去它给了我一个例外:对象引用未设置为对象的实例。
任何想法我能做些什么来解决这个问题?
非常感谢
仍然给我对象引用不设置到对象的实例。 – Karl
当您尝试查找使用row.FindControl时,未找到该复选框...您必须发布aspx标记以查找问题。 –
好的问题解决了,我通过了错误的文本框ID&如果应该已经如你所说感谢 – Karl