Repeater Control Problem

S

Sam Solomon

Dear All,

I have a Repeater Control which gets populated from the Database table.I
have a
separate column which has checkbox in it. So the last column of the repeater
control is a check box. Now I have a separate Button called delete . What I
want is that when I press the delete button I want all the rows in the
Repeater Control which have the check box clicked to be deleted from the
database.Basically I want to select all the rows and delete them by pressing
the delete button.

Below is my Code:


private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)

{

BindGrid();

}

}


void BindGrid()

{

SqlCommand cmdNorth;
SqlDataReader dtrNorth;
cmdNorth = new SqlCommand("Select EmployeeID,LastName,FirstName from
Employees",conNorth);
dtrNorth = cmdNorth.ExecuteReader();
Repeater1.DataSource=dtrNorth;
Repeater1.DataBind();
dtrNorth.Close();

}


private void Button1_Click(object sender, System.EventArgs e)
{
foreach(RepeaterItem rptRow in Repeater1.Items)

{
CheckBox ckhAuthors = (CheckBox)(rptRow.FindControl("ckhAuthors"));
if(ckhAuthors.Checked==true)
{

/****

What do I should write here???

******/
}
}

BindGrid();

}

<ItemTemplate>
<tr>
<td><%#DataBinder.Eval(Container.DataItem,"EmployeeID")%></td>
<td><%#DataBinder.Eval(Container.DataItem,"LastName")%></td>
<td><%#DataBinder.Eval(Container.DataItem,"FirstName")%></td>
<td><asp:CheckBox ID="ckhAuthors"
Text="Selected"=Runat="server"></asp:CheckBox></td>
</tr></ItemTemplate>

Any Help will be much appreciated.

Thanking you in Anticipation.

cheers,
Sam Solomon
 
M

mohammad asif

I don't know about the C# syntax. But this is what I do logically. What I am
assuming is that your EmployeeId is unique. Based on that, I would execute a
delete query . what you might wanna do for efficiency is create a stored
procedure for delete, and pass the employeeID of the row with a checkbox
checked.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top