updatepanel with multiple asp:repeaters

experts:

I have a repeater that loads data from a database. one column of the repeater contains a linkbutton. I'd like the linkbutton to load other repeaters within the same page. I currently have this working with the page doing a postback and passing a parameter in the url. I want to avoid this and populate the other repeaters without the postback using the AJAX update panel.

Can anyone point me in the right direction please?

Thanks
telliot79Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robert SchuttSoftware EngineerCommented:
The UpdatePanel does a partial postback so your code may need to be adjusted to handle that, how much depends a lot on your current code. It may not require much special, like in the simple example below. As long as you're aware of the ASP.NET page life-cycle it should be possible to resolve any problems that may arise.

Couple of notes in advance:
* I used UpdateMode="Conditional" on the UpdatePanel, this is actually only relevant if you have more than 1 UpdatePanel on your page;
* I use the OnLoad Event of the UpdatePanel since I found that simpler than other examples I found on the web using an invisible button;
* the LinkButton shows a postback call when you hover over it but that is negated by the OnClientClick. You could just as well just use an <a href>, the LinkButton as I use it is of no real use.

Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="EE_Q_28570879_WEB.Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title> EE Q_28570879 </title>
    <style type="text/css">
        .tophalf
        {
            height: 300px;
            overflow: auto;
        }
        .item
        {
            float: left;
            width: 18%;
            border: 1px solid green;
            margin: 2px;
            padding: 3px 6px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <div class="tophalf">
            <asp:Repeater ID="Repeater1" runat="server">
                <ItemTemplate>
                    <div class="item">
                        <asp:LinkButton ID="lbDetail" runat="server" OnClientClick='<%# Eval("ID", "return refreshChildData(&#39;{0}&#39;)") %>'>show details below</asp:LinkButton><br />
                        item id: <%# Eval("ID") %><br />
                        name: <%# Eval("Name") %>
                    </div>
                </ItemTemplate>
            </asp:Repeater>
        </div>
        <hr />
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" OnLoad="UpdatePanel1_Load">
            <ContentTemplate>
                <asp:Repeater ID="Repeater2" runat="server">
                    <ItemTemplate>
                        <div class="item">
                            child id: <%# Eval("ID") %><br />
                            name: <%# Eval("Name") %>
                        </div>
                    </ItemTemplate>
                </asp:Repeater>
            </ContentTemplate>
        </asp:UpdatePanel>
        <script type="text/javascript">
            function refreshChildData(id) {
                __doPostBack('<%=UpdatePanel1.UniqueID%>', id);
                return false;
            }
        </script>
    </div>
    </form>
</body>
</html>

Open in new window


Default.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;

namespace EE_Q_28570879_WEB {
    public partial class Default : System.Web.UI.Page {
        protected void Page_Load(object sender, EventArgs e) {
            if (!IsPostBack) {
                DataTable dt = new DataTable();
                dt.Columns.AddRange(new DataColumn[] { new DataColumn("ID", typeof(int)), new DataColumn("Name", typeof(string)) });
                for (int i = 0; i < 100; i++) {
                    dt.Rows.Add(new object[] { i, "Parent " + i });
                }
                Repeater1.DataSource = dt;
                Repeater1.DataBind();
            }
        }

        protected void UpdatePanel1_Load(object sender, EventArgs e) {
            if (IsPostBack && Request.Form["__EVENTTARGET"].ToString() == UpdatePanel1.UniqueID) {
                Repeater2.DataSource = GetChildData(Request.Form["__EVENTARGUMENT"].ToString());
                Repeater2.DataBind();
            }
        }

        private DataTable GetChildData(string p) {
            DataTable dt = new DataTable();
            dt.Columns.AddRange(new DataColumn[] { new DataColumn("ID", typeof(int)), new DataColumn("Name", typeof(string)) });
            for (int i = 0; i < 10; i++) {
                dt.Rows.Add(new object[] { i, "Child " + p + "." + (i + 1) });
            }
            return dt;
        }
    }
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
telliot79Author Commented:
excellent.

Thanks Robert Schutt. Much appreciated.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.