using
System;
using
System.Collections.Generic;
using
System.Linq;
using System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Configuration;
using
System.Data.SqlClient;
using
System.Data;
using
System.Collections.Specialized;
using
System.Text;
using
System.Collections;
namespace
DeleteMultipleRows
{
public partial
class
DeleteMultipleRows : System.Web.UI.Page
{
public string
connStr = ConfigurationManager.ConnectionStrings["BRS"].ConnectionString;
DataSet ds =
new DataSet();
string r;
protected
void Page_Load(object sender,
EventArgs e)
{
if (!IsPostBack)
{
datas();
}
}
private void
datas()
{
SqlConnection conn =
new SqlConnection(connStr);
conn.Open();
SqlCommand cmd =
new SqlCommand("Select
* from Tbl_BugReportingSystem", conn);
SqlDataAdapter ad =
new SqlDataAdapter(cmd);
DataSet ds =
new DataSet();
ad.Fill(ds, "Tbl_BugReportingSystem");
GrdReport.DataSource = ds;
GrdReport.DataBind();
}
protected
void grdclient_PageIndexChanging(object
sender, GridViewPageEventArgs e)
{
}
protected
void Grd_Download_RowDataBound(object
sender, GridViewRowEventArgs e)
{
if (e.Row.RowType ==
DataControlRowType.DataRow)
{
//int id =
Convert.ToInt16((e.Row.FindControl("lblBugId") as Label).Text);
//Functions
objfn = new Functions();
//DataTable
file = new DataTable();
//file =
objfn.GetAFile(id);
//DataRow row =
file.Rows[0];
//if
(file.DefaultView[0]["AttachmentName"].ToString().Trim() == "")
//{
// (e.Row.FindControl("Hyplnk_Attachments")
as HyperLink).Visible = false;
//}
}
}
protected
void GrdReport_SelectedIndexChanged(object
sender, EventArgs e)
{
}
protected
void btn1_Click(object sender,
EventArgs e)
{
StringCollection sc =
new
StringCollection();
//for (int i = 0; i
< GrdReport.Rows.Count; i++)
foreach (GridViewRow gvrow
in GrdReport.Rows)
{
CheckBox cb = (CheckBox)gvrow.FindControl("chk123");
//find the CheckBox
if (cb !=
null)
{
if (cb.Checked)
{
int usrid =
Convert.ToInt32(GrdReport.DataKeys[gvrow.RowIndex].Value);
//string id = GrdReport.Rows[i].Cells[1].Text;
sc.Add(usrid.ToString());
DeleteRecords(sc);
}
}
}
datas();
}
private void
DeleteRecords(StringCollection sc)
{
SqlConnection conn =
new SqlConnection(connStr);
//StringBuilder sb
= new StringBuilder(string.Empty);
try
{
conn.Open();
foreach (string
item in sc)
{
SqlCommand cmd =
new SqlCommand("delete
from Tbl_BugReportingSystem where BugId=" + item, conn);
cmd.ExecuteNonQuery();
}
}
catch (System.Data.SqlClient.SqlException
ex)
{
string msg =
"Deletion Error:";
msg += ex.Message;
throw
new Exception(msg);
}
finally
{
conn.Close();
}
}
}
}
Join the conversation! Your thoughts help the community grow.