Solved

Adding delete link for multiple item in a cell in Repeater control

Posted on 2008-10-24
3
836 Views
Last Modified: 2012-05-05
Hi,

I have a repeater control with following headings with sample data.

GroupName  Add Subject   SubjectName
----------------------------------------------------
Group1      Add Subject             subject1
                   Subject2
                   Subject3




When User Clicks on "Add Subject" I get the subject from the database for the group name and shows that in
SubjectName column.

Now I want to add delete functionality for the subject. So how can I add delete functionality in my code behind code.

Here is sample data.

GroupName  Add Subject   SubjectName
----------------------------------------------------
Group1      Add Subject             subject1         Delete
                   Subject2         Delete      
                   Subject3         Delete

Group2      Add Subject             subject4         Delete
                   Subject5         Delete
                   Subject6         Delete


Here is my sample code for adding subject when user clicks "AddSubject".




Please help me with this.





------------------------------------------------------------------------------------------------------------

 

   protected void Repeater1_ItemCommand(object source, DataListCommandEventArgs e)

    {

        int rowIndex = e.Item.ItemIndex;

        HiddenField hfSelectedEventName = (HiddenField)((DataList)source).Items[rowIndex].FindControl("hfSelectedEventName");

        HiddenField hfSelectedEventId = (HiddenField)((DataList)source).Items[rowIndex].FindControl("hfSelectedEventId");

       

       if (e.CommandName == "btnAdd")  // btnAdd is a link button in my repeater control

       {

            ((Panel)((DataList)source).Items[rowIndex].FindControl("PanelEvents")).Visible = false;

            ((Literal)((DataList)source).Items[rowIndex].FindControl("literalSelectedEvent")).Visible= true;

            CheckBoxList cblEvents = (CheckBoxList)((DataList)source).Items[rowIndex].FindControl("cblEvents");

            

     

            Literal literalSelectedEvent = (Literal)((DataList)source).Items[rowIndex].FindControl("literalSelectedEvent");

            TextBox txtNewEvent = (TextBox)((DataList)source).Items[rowIndex].FindControl("txtNewEvent");   

            StringBuilder strEventData=new StringBuilder();

            string strSelectedEvents = string.Empty;

            string strSelecedEventIds = string.Empty;

            int i=1;

          foreach (ListItem subject in cblEvents.Items)

           {

                 

               if (item.Selected)

               {

                   if (!hfSelectedEventName.Value.Contains(subject.Text))//check for edit mode

                   {

                       strSelectedEvents += subject.Text + ",";

                       strSelecedEventIds += subject.Value + ",";

                       strEventData.Append("<div>" + subject.Text + "</div>");  // I want to add "delete" link here.

                         

                       i++;

                   }

               }

 

              

           }

          if (strSelectedEvents.Length > 1)

          {

              strSelectedEvents = strSelectedEvents.Substring(0, strSelectedEvents.Length - 1);

              strSelecedEventIds = strSelecedEventIds.Substring(0, strSelecedEventIds.Length - 1);

          }

 

          if (txtNewEvent.Text != string.Empty)

          {

           strSelectedEvents+=","+txtNewEvent.Text;

           strSelecedEventIds += ",0";

           strEventData.Append("<div>" + txtNewEvent.Text + "</div>");

               

                      

              txtNewEvent.ReadOnly=true;

          }

          if (strSelectedEvents != string.Empty)

          {

              hfSelectedEventName.Value = strSelectedEvents;

              hfSelectedEventId.Value = strSelecedEventIds;

              literalSelectedEvent.Text += strEventData.ToString();

          }

           

       }

   }

 

-----------------------------------------------------------------------------------------------------------------------------

Open in new window

0
Comment
Question by:r_pat72
3 Comments
 
LVL 16

Accepted Solution

by:
Gyanendra Singh earned 500 total points
Comment Utility
use this
<ItemTemplate>
        <div style="float:left; padding:10px; text-align:center;">
           <asp:HyperLink OnClientClick="return confirm('Are you sure?');" ID="DeleteLink" runat="server" NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "ImageId","yourpage.aspx?PropertyId="+Request.QueryString("yourID")") %>'  >Delete</asp:HyperLink>
        </div>
        </ItemTemplate>
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Using Quotation Marks in PHP This question (http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28217211.html) seems to come up a lot for developers who are new to PHP.  And it got me thinking, "How can we explain the rule…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now