Hello all,
I have designed an address book where gridview bind with the address details with check option.there is also an dropdownlist out of the gridview which populate with the group. If you click on that dropdownlist then the gridview bind the data according to the selected group.
If I click on the selected all then the selected data of the particular grops data are deleted form the table "Addressbook" using linq
I've used 2 tables
1.groups
2.addressbook
groupid is fk in addressbook which is auto generated key.
I have already written code for delete with select all
the code is
for (int i = 0; i < GridView1.Rows.Count; i++)
{
System.Web.UI.WebControls.CheckBox cbb = (System.Web.UI.WebControls.CheckBox)GridView1.Rows[i].FindControl("chkbox");
if (cbb.Checked == true)
{
int id = Convert.ToInt32(GridView1.Rows[i].Cells[1].Text);
alist.Add(id);
}
}
using (RealEstateDataClassesDataContext db = new RealEstateDataClassesDataContext())
{
for (int j = 0; j < alist.Count; j++)
{
int id = Convert.ToInt32(alist[j]);
var info = from p in db.AddressBooks
where p.Addbook_ID == id
select p;
foreach (var deleteinfo in info)
{
db.AddressBooks.DeleteOnSubmit(deleteinfo);
}
try
{
db.SubmitChanges();
}
catch (Exception ex)
{
Response.Write("Error:" + ex.Message);
}
when the dropdownlist selected value as all then it is works.
but when I select a particular group from dropdownlist and the select all and click on the button the it shows me error.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 148:
Line 149: System.Web.UI.WebControls.CheckBox cbb = (System.Web.UI.WebControls.CheckBox)GridView1.Rows[i].FindControl("chkbox")
Line 150: if (cbb.Checked == true)
Line 151: {
Line 152: int id = Convert.ToInt32(GridView1.Rows[i].Cells[1].Text)
for more details please visit the site
http://php-addressbook.sourceforge.net/demo/[
^]
Thanks in advance!