0

I am developing Canteen Management System where I am displaying menuList from Database using gridview like given below.. ( this is Menu.aspx page)

<asp:DataList ID="DataList1" runat="server" RepeatColumns="3" RepeatDirection="Horizontal" OnItemCommand="DataList1_ItemCommand">
    <ItemTemplate>
        <table class="nav-justified" style="height: 111px">
            <tr>
                <td>
                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("menuName") %>'></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:ImageButton ID="ImageButton1" runat="server" CommandName="viewDetail" CommandArgument='<%# Eval("Id") %>' ImageUrl='<%# Eval("menuImage") %>' />
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="Label2" runat="server" Text='<%# Eval("menuPrice") %>'></asp:Label>
                </td>
            </tr>
        </table>
    </ItemTemplate>
</asp:DataList>
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Cms_AspFormsConnectionString %>" SelectCommand="SELECT [menuName], [menuPrice], [menuImage], [Id] FROM [menuInfo]"></asp:SqlDataSource>

This is Menu.aspx.cs page

protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
    if ( e.CommandName == "viewDetail" )
    {
        Response.Redirect("MenuDetails.aspx?Id=" + e.CommandArgument.ToString());
    }
}

but When i run this this it's showing nothing, ( when i go to source page it was all empty at like given below..)

<div>
        
        <br />
   
</div>

Why it' showing empty? and how to resolve this?

1
  • Well, in your event code, does a debug.print e.commandArugment show any value before you jump to the other page? and if you type in the id by hand into the url, does the other page work?? Commented Oct 15, 2021 at 22:20

1 Answer 1

0

Add DataSourceID="SqlDataSource1" to the DataList tag. Data source was not set for the control.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.