如何获得GridView里的值?
z825 2010-10-26 02:37:12 我在C#程序里加了GridView和绑定了数据,在作删除数据库里的选定行动作的时候,取不出选定的ID,我的代码是以下
protected void Delete_Sel_Click(object sender, EventArgs e)
{
foreach (GridViewRow gr in GridView1.Rows)
{
CheckBox chk = (CheckBox)gr.Cells[16].FindControl("itemSel");
if (chk.Checked)
{
TextBox txt = (TextBox)gr.Cells[2].FindControl("ProjectName");
string aa = txt.Text;
//string aa = ((TextBox)gr.Cells[2].FindControl("ProjectName")).Text;
WebMessageBox(aa);
}
}
}
public void WebMessageBox(string values)
{
HttpContext.Current.Response.Write("<script>alert('" + values + "');history.back()</script>");
HttpContext.Current.Response.End();
}
,但老是提示出错“Object reference not set to an instance of an object” ,在string aa = txt.Text;的一句出错。我换了“string aa = ((TextBox)gr.Cells[2].FindControl("ProjectName")).Text; ”请帮我看看我的问题出在哪?如何取得GridView里的ProjectName段的值?