Hi,
Myself Vishwasdeep. I am doing a project work on asp.net. I am getting an error/exception on my code.
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.Sql;
using System.Data.SqlClient;
namespace WebApplication2
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
DataColumn dc = new DataColumn("id", typeof(string));
dt.Columns.Add(dc);
DataColumn dc1 = new DataColumn("name", typeof(string));
dt.Columns.Add(dc1);
foreach (GridViewRow grow in GridView1.Rows)
{
CheckBox cbox = (CheckBox)grow.FindControl("cbox");
if (cbox.Checked == true) // i am getting exception here ,Object reference not set to an instance of an object.//
{
DataRow dr = dt.NewRow();
dr["id"] = grow.Cells[0].Text;
dr["name"] = grow.Cells[1].Text;
dt.Rows.Add(dr);
}
}
ds.Tables.Add(dt);
GridView2.DataSource = ds;
GridView2.DataBind();
}
}
}
Plz anyone can help to solve this exception as soon as possible.
Regards,
Vishwasdeep