Repeater Control Problem

Discussion in 'ASP .Net Web Controls' started by Sam Solomon, Sep 20, 2005.

  1. Sam Solomon

    Sam Solomon Guest

    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
    Sam Solomon, Sep 20, 2005
    #1
    1. Advertising

  2. 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.
    "Sam Solomon" <Sam > wrote in message
    news:...
    > 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
    >
    >
    mohammad asif, Sep 21, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    851
  2. Replies:
    0
    Views:
    2,878
  3. Replies:
    1
    Views:
    7,018
    Karl Seguin
    Aug 10, 2005
  4. uncensored
    Replies:
    0
    Views:
    811
    uncensored
    Oct 25, 2006
  5. Microsoft

    Repeater inside a Repeater

    Microsoft, Aug 21, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    205
    Microsoft
    Aug 21, 2006
Loading...

Share This Page