Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
If no products exists in database or if there is no products to display, then wants to display like 'no products to display'.
How to do that.
This is the code i have used to display products

C#
private void BindGridData()
    {
        try
        {
            con.Open();
            string menuid = Application["MenuId"].ToString();
            {
                string sql = "select * from rsa_ProductItemTable where MenuId=" + menuid;
                SqlCommand cmd = new SqlCommand(sql, con);
                SqlDataAdapter da = new SqlDataAdapter(sql, con);
                DataSet ds = new DataSet();
                da.Fill(ds);
                DataList1.DataSource = ds;
                DataList1.DataBind();
                }
            }

        catch (Exception ex)
        {
        }
        finally
        {
            con.Close();
        }
        }


Please Help me with this.
Posted
Updated 29-Dec-14 6:31am
v2
Comments
ridoy 29-Dec-14 12:56pm    
You can check: http://www.mikesdotnetting.com/article/214/how-to-check-if-a-query-returns-data-in-asp-net-web-pages

Add footer template like below [^]
ASP.NET
<FooterTemplate>
<asp:Label Visible='<%#bool.Parse((DataList1.Items.Count==0).ToString())%>' runat="server" ID="lblNoRecord" Text="No Record Found!"></asp:Label>
</FooterTemplate>
 
Share this answer
 
v2
Comments
joginder-banger 31-Dec-14 1:22am    
Good Answer sir..
This is very easy to implement if you are using a GridView control provided by .net framework.

STEPS
1. Open the smart tag of the gridview, at the bottom, select Edit Templates. (The smart tag is the little button with a foward arrow on top
of the control)
2. Select from the dropdownlist, Empty Data Template.
3. Enter a message to display in the content area of the gridview that will come up.

You can style the content, use image and more. After doing that, click on End Editing to finish process.

Give it a go, don't forget to mark as correct answer if it works for you..
 
Share this answer
 
v2
Comments
kwelpooh 29-Dec-14 12:38pm    
not using gridview control using Datalist to display products for example if iam clicking watches no products in database i wants to display "no products to display"
how to do that in if condition.
[no name] 29-Dec-14 12:59pm    
It is also available in a DataList as well but if you want it via query, do something like this.

Dim cmd as New SqlCommand()
cmd.CommandText = "SELECT * FROM tblProducts"
Dim rd as SqlDataReader = cmd.ExecuteReader()
If rd.HasRows = False Then
//Display message or write to an object
End If
rd.Close

Convert it to C#, I understand VB better. Try it out

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900