2017-01-16 66 views
0

我的问题是当我点击产品页面(在下面的URL中)。它工作良好,但经过一段时间后首先点击产品菜单,它不会将产品图像从数据库加载到Repeater控制。经过一段空闲时间后,图像无法从数据库加载

我正在使用Bootstrap而不使用更新面板。

请参阅下面的链接。 MySite(See Product Page On First Time And Click After 5 to 10 minute of idle time)

我ASP.net代码

<asp:Repeater ID="rptrProduct" runat="server"> 
        <ItemTemplate> 
         <div class="portfolio-item col-xs-12 col-sm-4 col-md-3"> 
          <div class="recent-work-wrap hovereffect"> 
           <img id="dtimg1" runat="server" class="img-responsive imggray" src='<%#Eval("ImagePath")%>' alt="" style="height: 185px!Important;" /> 
           <div class="overlay1"> 
            <div class="recent-work-inner"> 
             <a id="aimg2" runat="server" href='<%#Eval("ImagePath")%>' rel="prettyPhoto"> 
              <h2> 
               <%#Eval("ProductName")%></h2> 
             </a> 
             <p> 
              <a id="adtimg1" runat="server" class="preview" href='<%# string.Format("~/BMSubProduct.aspx?pro={0}", Eval("ProductId")) %>'> 
               <i class="fa fa-eye"></i>View Products</a> 
             </p> 
            </div> 
           </div> 
          </div> 
         </div> 
        </ItemTemplate> 
       </asp:Repeater> 

我只是没有得到那为什么第一次不会加载任何图像。

我的C#网页代码

if(!Page.IsPostBack) 
{ 
     DataTable dt = DBMaster.getQueryDataTableSchema(query); 
     if (dt.Rows.Count > 0) 
     { 
      string path = GlobalFunction.getPath(1); 
      NoProducts.Visible = false; 
      for (int i = 0; i < dt.Rows.Count; i++) 
       dt.Rows[i]["ImagePath"] = path + Convert.ToString(dt.Rows[i] ["ImagePath"]); 
      rptrProduct.DataSource = dt; 
      rptrProduct.DataBind(); 
     } 
     else 
     { 
      NoProducts.Visible = true; 
      rptrProduct.DataSource = null; 
      rptrProduct.DataBind(); 
     } 
    } 
    public static DataTable getQueryDataTableSchema(string query) 
    { 
    try 
    { 
     using (IDbConnection con = sq.Open()) 
     { 
      IDbCommand cmd = con.CreateCommand(); 
      cmd.CommandText = query; 
      IDbDataAdapter adp = sq.GetAdapter(cmd); 
      DataSet ds = new DataSet(); 
      adp.FillSchema(ds, SchemaType.Source); 
      adp.Fill(ds); 
      con.Close(); 
      return ds.Tables[0]; 
     } 
    } 
    catch (Exception ex) 
    { 
     return new DataTable(); 
    } 
} 

和母版的代码在Page_Load中是

if (!Page.IsPostBack) 
    { 
     SQLString.Config = myconnectionString; 
    } 

这里NoProduct => No Products Are Available Right Now.

我已经尝试了类似下面的东西:

  1. EnableViewState="true"EnableViewState="false"都适用于中继器和页面。在web.config中

  2. 更改连接字符串像

    name="SQLConStr" connectionString="Server=localhost;Database=databasename; Uid = username; Pwd = password; Pooling = false; Connection Timeout = 30" 
    

这里试图与不连接超时和池。

注意事项:使用MySQL数据库并使用接口打开数据库连接。

在此先感谢。

+0

理想的时间?难道你的意思是'空闲'? – Frank

+0

您提供的链接得到:“没有产品现在可用”。 EnableViewState必须为true。你在ImagePath中得到什么?什么在“路径”?也许可以在全球路径和路径之间的斜线错过? – Emanuele

+0

@Emanuele,但当第二次点击同一链接时,它会得到加载图像.. –

回答

0

EnableViewState="true"

,并尝试使用

<asp:Image<asp:HyperLink控制

,而不是

IMG与RUNAT = “服务器” 下的标签。

+0

感谢您的重播..有以下解决方案的解决方案。 1)。从主页Page_Load中移除连接字符串,并将该分配保留在主页Page_Init中。并将html控件更改为asp控件。 –

相关问题