2017-01-18 8 views
1

価格や製品情報などの製品イメージを表示できるWebページを設計しようとしています。データベースからデータをバインドしてプログラムを実行すると、ページは空白になります。何も表示されません。私はエンティティフレームワーク、ブートストラップなどを使用して試してみました。同じ結果です。私のシステムは、Windowsの8.1とビジュアルスタジオ2013究極の.Netフレームワークを使用して4.5私はSSMSのデータベースとVisualスタジオのMDFデータベースを使用してみました..何も変更...何か助けはありますか?または追加のアドオンが必要ですか、または間違ったコーディングがありますか? ありがとうございました... 以下は私のコードです。バインドしてデータベースASP.netのデータを表示しようとすると、私のページが空白になる理由

ソースコード:

<%@ 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> 

の背後にあるコード:

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(); 
      } 
     } 
    } 
} 
} 
+1

ような何かを行う場合 だ場合は、ページがロードされたときに

はまた、私はあなたがデータをロードしたいと考えています。もしそうでなければ、あなたの問題はそれかもしれません。また、なぜあなたはポストバックでこれをやっていますか?それはあなたが欲しいものですか? – CodingYoshi

答えて

0
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()); 
} 

かどうかを確認もしそうなら、このような何かを試してみて、デバッグ中にデータテーブルにレコードを取得するかどうかを確認データリターンは、データをバインドするためにリピーターで使用されているのと同じ列名を持ちます。それがブレークポイントを入れて、 `dtBrands`はそれで任意の行を持っているかどうか、この

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

'Response.Write(Ex.Message.ToString());'コンソールはasp.Netで無視されるだけなので、コンソールはありません。 – CodingYoshi

関連する問題