Home > ASP.Net > Delete an item from Repeater having checkbox

Delete an item from Repeater having checkbox


Hi

try this example:

<asp:Repeater ID="Repeater1" runat="server" >
    <ItemTemplate>
        <asp: Panel ID="Container" runat="server">
            <asp:Literal ID="litID" runat="server" Text='<%# Eval("PrimaryKeyField") %>' Visible="false"></asp:Literal>
            <asp:CheckBox ID="chkflag" runat="server" />
        </asp: Panel>
    </ItemTemplate>
</asp:Repeater>

Delete Button Click :

 

   protected void Button1_Click(object sender, EventArgs e)
    {
        bool BindNeeded = false;
        foreach (RepeaterItem ri in Repeater1.Items)
        {
            CheckBox chkFlag = ri.FindControl("chkflag") as CheckBox;
            if (chkFlag.Checked)
            {
                int Key = Convert.ToInt32((ri.FindControl("litID") as  Literal).Text);
                if (DALClass.Delete(Key))
                    if (BindNeeded == false) BindNeeded = true;

            }
       
        }
        // if the delete happened , we refresh the data in repeater
        if (BindNeeded) Repeater1.DataBind();
    } 

Good Luck

Advertisements
Categories: ASP.Net
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: