简体   繁体   中英

Why my page goes blank after binding and trying to display data from database ASP.net

I'm trying to design some webpage where I can display my product images including price and product information. After binding the Data from the database and run the program, the page goes blank. Nothing displays. I've tried using entity framework, using Bootstraps, etc. Same result. My system is Windows 8.1 and visual studio 2013 ultimate using .Net framwork 4.5 I've tried using SSMS dataBase and Visual studio MDF database.. nothing changes... Is there any help? or Do I need additional add=ons or Is there any wrong codding ? thank guys... below is my code.

source code:

<%@ Page Title="" Language="C#" MasterPageFile="~/UsserMasterPage.master" AutoEventWireup="true" CodeFile="Products.aspx.cs" Inherits="Products" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div class="row" style="padding-top: 50px">
        <asp:Repeater ID="rptrProducts" runat="server">
            <ItemTemplate>
                <div class="col-sm-2 col-md-2">
                    <div class="thumbnail">
                        <img src="Images/ProductImages/<%#Eval("PID") %>/<%#Eval("ImageName") %><%#Eval("Extention") %>" alt="<%#Eval("ImageName") %>" />
                        <div class="caption">
                            <div class="proBrand"><%#Eval("BrandName") %></div>
                            <div class="proName"><%#Eval("ProductName") %></div>
                            <div class="proPrice"><span class="proOgPrice"><%#Eval("ProductPrice") %></span><%#Eval("ProductSellPrice") %><span class="proPriceDiscount"><%#Eval("DiscAmount") %>Off</span></div>
                        </div>
                    </div>
                </div>
            </ItemTemplate>
        </asp:Repeater>
    </div>
</asp:Content>

Code behind:

protected void Page_Load(object sender, EventArgs e)
{
    if(IsPostBack)
    {
        BindProductRepeater();
    }
}

private void BindProductRepeater()
{
    String SC = ConfigurationManager.ConnectionStrings["ShoppingDBConnectionString1"].ConnectionString;
    using(SqlConnection con = new SqlConnection(SC))
    {
        using (SqlCommand cmd = new SqlCommand("ProcedureBindAllProducts", con))
        {
            cmd.CommandType = CommandType.StoredProcedure;
            using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
            {
                DataTable dtBrands = new DataTable();
                sda.Fill(dtBrands);
                rptrProducts.DataSource= dtBrands;
                rptrProducts.DataBind();
            }
        }
    }
}
}
try
{
  SqlCommand cmd = new SqlCommand("ProcedureBindAllProducts",con);
  DataTable dt = new DataTable();
  dt.Load(cmd.ExecuteReader());
  rptrProducts.DataSource= dtBrands;
  rptrProducts.DataBind();
}
catch(Exception Ex)
{
  Console.WriteLine(Ex.Message.ToString());
}

Try Something like this and see if the data table gets any records while debugging if so check if the data returns have the same column names which are being used at the repeater to bind data.

Also I believe you want to load data when page is loading if that's the case do something like this

protected void Page_Load(object sender, EventArgs e)
{
  if(!IsPostBack)
  {
    BindProductRepeater();
  }
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM