Friday, January 25, 2008

Delete Selected Rows in GridView in ASP.Net 2.0

protected void Button_DelProp_Click(object sender, EventArgs e)

{

Select_CheckBox();

if (_newId == "")

{

ClientScript.RegisterStartupScript( this.GetType(), "script", "");

}

else

{

string strcmd = "DELETE FROM Registered_Properties WHERE (Property_Id IN (" + _newId + ") )";

SqlCommand cmd = new SqlCommand(strcmd, con);

con.Open();

cmd.ExecuteNonQuery();

con.Close();

Response.Redirect(Session["Page"].ToString());

}

}

private void Select_CheckBox()

{

string Id = "";

for (int i = 0; i <>

{

bool chkSelect = (((CheckBox) GridView1.Rows[i].FindControl ("Chkselect")).Checked);

if (chkSelect)

{

Label lblPId = new Label();

lblPId = (Label)GridView1.Rows[i].FindControl("Label_PId");

Id += "," + lblPId.Text.ToString();

}

}

_newId = Id.Trim(',');

}

-
ShriKrishna Bhardwaj , With ASP.Net, SQL Server, Javascript

No comments: