Click here to Skip to main content
15,901,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this code not properly work i want to delete the selected row by using checkbox in template field in grid view

protected void Page_Load(object sender, EventArgs e)
if (!Page.IsPostBack)

DataTable table;

protected void GridView3_RowDeleting(object sender, GridViewDeleteEventArgs e)
int row = e.RowIndex;

// Temp.Rows[row].Delete();

private void BindData()
string constr = @"Data Source=RESTON-PC;Initial Catalog=DCompany;Integrated Security=True";
string query = @"SELECT * FROM AircraftInfo";

SqlDataAdapter da = new SqlDataAdapter(query, constr);
table = new DataTable();

GridView3.DataSource = table;

But it give 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 28: {
Line 29: int row = e.RowIndex;
Line 30: table.Rows[row].Delete();
Line 31:
Updated 26-Oct-12 2:22am

I suggest when you click the check box, the event should 1st get the ID or record ID of the row, then pass that ID to your sql statement.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900