我的問題是當我點擊產品頁面(在下面的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.
我已經嘗試了類似下面的東西:
EnableViewState="true"
和EnableViewState="false"
都適用於中繼器和頁面。在web.config中更改連接字符串像
name="SQLConStr" connectionString="Server=localhost;Database=databasename; Uid = username; Pwd = password; Pooling = false; Connection Timeout = 30"
這裏試圖與不連接超時和池。
注意事項:使用MySQL
數據庫並使用接口打開數據庫連接。
在此先感謝。
理想的時間?難道你的意思是'空閒'? – Frank
您提供的鏈接得到:「沒有產品現在可用」。 EnableViewState必須爲true。你在ImagePath中得到什麼?什麼在「路徑」?也許可以在全球路徑和路徑之間的斜線錯過? – Emanuele
@Emanuele,但當第二次點擊同一鏈接時,它會得到加載圖像.. –