Click here to Skip to main content
15,949,686 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)
{
BindData();
}

}
DataTable table;

protected void GridView3_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int row = e.RowIndex;
table.Rows[row].Delete();



// 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();


da.Fill(table);
GridView3.DataSource = table;
GridView3.DataBind();
}

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:
Posted
Updated 26-Oct-12 2:22am
v2

Hi
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