I have a repeater in my webpage which containing Buttons as well..

        <asp:Repeater ID="rptView" runat="server" OnItemDataBound="rptView_ItemDataBound">
            <HeaderTemplate>
                <table border="0" width="90%">
                    <tr class="RepeaterHeader">
                        <th align="center">Date</th>
                        <th align="center">Category</th>
                        <th align="center">Description</th>
                        <th align="center">Amount</th>
                        <th align="center"></th>
                    </tr>
            </HeaderTemplate>
            <ItemTemplate>
                <tr class="RepeaterData">
                    <td align="center"><%#Eval("CurrentDate") %></td>
                    <td align="center"><%#Eval("Category") %></td>
                    <td align="center"><%#Eval("Description") %></td>
                    <td align="center"><%#Eval("Amount", "{0:C}")%></td>
                    <td align="center"><asp:Button ID="btnDelete" runat="server" Text="Delete" CssClass="Button" OnClick="Remove" /></td>
                </tr>
            </ItemTemplate>

i want detect which row of the Button is exaclty clicked,
then i have to retrieve the value of Category of the Button clicked row due to remove the data.
Any way is able to retrieve data of the repeater from code behind?

Recommended Answers

All 9 Replies

I'm thinking based on your description that you should use OnCommand instead of Onclick. With OnCommand use CommandName so you can retreive the category name so you can complete the processing.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.oncommand.aspx

 <asp:Button ID="btnDelete" runat="server" Text="Delete" CssClass="Button" OnComand="Remove" CommandName="<% Eval("Category") %>" />

how about i want retrieve multiple data?

Cannot Use CommandName and OnCommand Property due to

Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 

Parser Error Message: Server tags cannot contain <% ... %> constructs.
 <asp:Button ID="btnDelete" runat="server" Text="Delete" CssClass="Button" OnComand="Remove" CommandName=<%#Eval("Category") %> />

The Parser Error is Encountered.
But i still have no idea how to retrieve multiple value and how about code behind if using CommandName=<%#Eval("Category")%>?

I am trying to display the Category data and the error i got.

Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

Code Behind

protected void Remove(object sender, CommandEventArgs e)
{
    Response.Write(e.CommandName.ToString());           
}

Hmm.. I'll research this some more...

Is a gridview control not an option?

A gridview also okay. As long as able to remove particular data from database :)

GridView is solved.

I realise you have probably already moved on from this, but for posterity sake...

CommandName=<%#Eval("Category")%>

you need quotes when specifying server values, which is probably the cause of the parsing error.

CommandName='<%#Eval("Category")%>'
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.