1
Gridview
正確填充返回數據時,但是ShowHeaderWhenEmpty
,EmptyDataText
,並且EmptyDataTemplate
都不起作用,即使沒有記錄返回。我已經閱讀了關於CSSFriendly的其他解決方案以及CSSFriendly禁用控件的一些衝突,但是這似乎沒有解決問題。ShowHeaderWhenEmpty,EmptyDataText和EmptyDataTemplate不是在GridView的工作
這裏是我的ASP gridview
<asp:GridView runat="server" class="table table-striped table-hover" ID="gvPendingRequestsEP" GridLines="None" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="submitted_by" HeaderText="submitted by" />
<asp:BoundField DataField="date_submitted" HeaderText="date submitted" />
<asp:BoundField DataField="card_number" HeaderText="Card Number" />
<asp:BoundField DataField="beginning_date" HeaderText="Date" />
<asp:BoundField DataField="beginning_time" HeaderText="time" />
<asp:BoundField DataField="total_time" HeaderText="hours" />
<asp:BoundField DataField="in_place_rank" HeaderText="Time/ Pay" />
<asp:BoundField DataField="status_id" HeaderText="Status" />
<asp:TemplateField>
<HeaderTemplate>
edit
</HeaderTemplate>
<ItemTemplate>
<a href="EPRequest.aspx?id=<%#Eval("card_number") %>">edit</a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
這裏是我的代碼隱藏
protected void PopulateCardManagers(object sender, EventArgs e)
{
string connstring = ConfigurationManager.ConnectionStrings["TimeHubDBCS"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connstring))
{
SqlCommand cmdFillEP = new SqlCommand();
cmdFillEP = new SqlCommand("spSelectPendingRequestsEP", conn);
cmdFillEP.CommandType = System.Data.CommandType.StoredProcedure;
cmdFillEP.Parameters.Add("@UserId", SqlDbType.VarChar).Value = lblUserLoggedIn.Text;
DataSet dsRequests = new DataSet();
DataTable dtEPCards;
dsRequests.Tables.Add("dtEPCards");
dtEPCards = dsRequests.Tables[0];
SqlDataAdapter daPendingRequestsEP = new SqlDataAdapter();
daPendingRequestsEP.SelectCommand = cmdFillEP;
conn.Open();
try
{
daPendingRequestsEP.Fill(dtEPCards);
gvPendingRequestsEP.DataSource = dtEPCards;
gvPendingRequestsEP.DataBind();
}
catch (Exception ex)
{
PopupTitle = "error populating EP Card Manager: ";
message = ex.Message;
ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup('" + message + ex.Message + "');", true);
}
}
}
在此先感謝
您確定沒有發生異常嗎?嘗試在異常塊中執行Response.Write,因爲它可能會禁止顯示空模板。 – Abbath
當您設置ShowHeaderWhenEmpty並且沒有顯示任何內容時,即使您的代碼將您的網格綁定到數據源,也可能意味着您的數據源爲空。你可以通過故意將一個空的數據表加載到你的網格來避免這種情況 – JustLearning
@CosmosBanda,看起來像是這個問題。我添加了一個if/else塊來測試datatable是否爲null,如果是的話,綁定一個空的datatable到gridview。如果你想在下面添加它,我會給你答案,否則我只會寫和回答自己。謝謝! – StateofDK