compilation error: oncommand and CommandArgument in LinkButton

1k views Asked by At

I have a LinkButton in a repeater on my aspx page and I am calling a function oncommand and passing a parameter via CommandArgument but it is giving me compilation error. what am I missing here?? what should I do to fix this problem?

aspx code:

    <asp:Repeater id="rptProduct" runat="server">
            <HeaderTemplate>
                <table border="0" width="100%">
                    <tr style="background-color:blue">
                        <th align="center"><asp:Label ID="lblProduct" ForeColor="White" runat="server" Text="PRODUCT CATAGORIES"></asp:Label></th>
                    </tr>
                    <tr></tr>
                    <tr></tr>
                    <tr></tr>
                    <tr></tr>
            </HeaderTemplate>

            <ItemTemplate>

                    <tr style="background-color:cadetblue">
                        <td align="center"><asp:LinkButton ID="lbType" ForeColor="White" Font-Underline="false"
                         OnCommand="LoadGrid" CommandArgument='<%# Eval("ItemTypeNumber") %>'
                         Font-Bold="true" runat="server" Text='<%# Eval("ItemTypeDescription").ToString() %>'></asp:LinkButton></td>
                    </tr>
            </ItemTemplate>

            <%--<SeparatorTemplate>
                    <tr>
                        <td colspan="6"><hr></td>
                    </tr>
            </SeparatorTemplate>--%>

            <FooterTemplate>
                </table>
            </FooterTemplate>
        </asp:Repeater>

aspx.cs Page:

protected void LoadGrid(int typeno)
    {
        DataSet ds = new DataSet();
        ds = new UsersBLL().GetItemDetails(typeno);
        gvDetails.DataSource = ds;
        gvDetails.DataBind();
    }

Error: Compiler Error Message: CS0123: No overload for 'LoadGrid' matches delegate 'System.Web.UI.WebControls.CommandEventHandler'

1

There are 1 answers

5
Arindam Nayak On BEST ANSWER

It has to match with following method signature.

protected void LoadGrid(object sender, CommandEventArgs e)
{
  // e.CommandArgument -- this will get you typeno 
}