Mehmet Akif
Mehmet Akif

Reputation: 33

Pulling data from repeater without page postback

When I click the button in the repeater, I want to get the data about the relevant row. But without the page postback. I want to use UpdatePanel but I couldn't figure out how to do it. Can you help me?


Here are sample codes:
<asp:Repeater ID="rptCariler" runat="server">
    <ItemTemplate>
        <tr>
            <td><%#Eval("CariKodu") %></td>
            <td><%#Eval("CariUnvani") %></td>
            <td><%#Eval("CariGrubu") %></td>
            <td><%#Eval("AdSoyad") %></td>
            <td><%#Eval("Borc") %></td>
            <td><%#Eval("Alacak") %></td>
            <td><%#Eval("Bakiye") %></td>
            <td class="xsml">
                <asp:LinkButton ID="lbGetValue" runat="server" OnClick="GetValue"><span><i class="fas fa-trash-alt"></i></span></asp:LinkButton>
            </td>
        </tr>
    </ItemTemplate>
</asp:Repeater>

Upvotes: 0

Views: 99

Answers (1)

Albert D. Kallal
Albert D. Kallal

Reputation: 48989

Well, you don't note if you need the info client side, or server side?

I mean, if you drop the whole repeater into a update panel then you don't get a full page post back.

You would (should) then tag the controls as server side. Assuming the whole repeater inside of a update panel, say like this:

<asp:Repeater ID="r2" runat="server">
 <ItemTemplate>
    <table id="mytable" runat="server">
    <tr>
        <td><%#Eval("HotelName") %></td>
        <td><%#Eval("City") %></td>
        <td>
            <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">LinkButton</asp:LinkButton>
        </td>
    </tr>
    </table>
    <br />
    </ItemTemplate>
</asp:Repeater>

So now the code behind can work like this:

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        
        LinkButton mybutton = (LinkButton)sender;

        RepeaterItem repItem = (RepeaterItem)mybutton.Parent.Parent.Parent.Parent ;

        HtmlTableRow rRow = (HtmlTableRow)mybutton.Parent.Parent;

        Debug.WriteLine("Repeater index click = " + repItem.ItemIndex);
        Debug.WriteLine(rRow.Cells[0].InnerText);
        Debug.WriteLine(rRow.Cells[1].InnerText);
    }

This much comes down to if you want code behind here.

I mean, I would use a gridview, or listview if this is a table of data - you have better options for a "grid" of data in place of a repeater.

Upvotes: 1

Related Questions