views:

590

answers:

3

I have a repeater that displays some data from a SQL query:

<asp:Repeater runat="server" ID="damQuickList" OnItemDataBound="damQuickList_OnItemDataBound">
    <HeaderTemplate>
        <ul>
    </HeaderTemplate>

    <ItemTemplate>
        <li><asp:HyperLink runat="server" ID="damAnchor" /></li>
    </ItemTemplate>

    <FooterTemplate>
        </ul>
    </FooterTemplate>
</asp:Repeater>

In the codebehind:

damQuickList.DataSource = (Data.RunSelectQuery("SELECT * FROM Table ORDER BY " + radioButton.Value));
damQuickList.DataBind();

Is there a way to change the DataSource and have it update in the Repeater, without having to do a postback in the page (like how AJAX does it)? I've been using the Async controls I found here: http://www.asynccontrols.com/, but there's some issues using them with IE6/7.

+1  A: 

Off-topic: I hope that's not your real code; I'm pretty sure a malicious user could put anything they wanted into the radioButton.Value field and SQL-Inject you.

Aric TenEyck
Argh, good point. That's not my real code but it's very similar to it. Thanks for the catch, I'll hard-code the SQL queries and select them using integers.
Daniel T.
A: 

Do you mean a full round trip? Can you not put the repeater inside an UpdatePanel?

Mark Redman
A: 

Use the ASP.NET AJAX components. Put a ScriptManager on your page, then put a UpdatePanel on your page. Inside the update panels ContentTemplate put your repeater.

A quick example would look something like this...

ASPX Markup

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>

        <table>
            <asp:Repeater ID="Repeater1" runat="server">
                <ItemTemplate>
                    <tr>
                        <td>
                           <%# Eval("Data") %>
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>
        </table>

        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />

    </ContentTemplate>
</asp:UpdatePanel>

C# Code Behind

protected void Button1_Click(object sender, EventArgs e)
{
    Repeater1.DataSource = yourDataSource;
    Repeater1.DataBind();
}

Note the button that 'refreshes' your data source is also inside the content template. Hope it helps.

Chalkey