1.放一个label
- DataTable table = new DataTable();
- repeater1.DataSource = table;
- repeater1.DataBind();
- if (table.Rows.Count == 0)//或者 repAcctLedger.Items.Count == 0
- {
- label1.Text = "暂无查询结果";
- }
- else
- {
- label1.Text = "";
- }
DataTable table = new DataTable();
repeater1.DataSource = table;
repeater1.DataBind();
if (table.Rows.Count == 0)//或者 repAcctLedger.Items.Count == 0
{
label1.Text = "暂无查询结果";
}
else
{
label1.Text = "";
}
2.在FooterTemplate模板中放一个label
- <FooterTemplate>
- <td style="height: 16px">
- <asp:Label ID="Label1" runat="server" Text="暂无检索记录!" Visible="false"></asp:Label>
- </td>
- </FooterTemplate>
<FooterTemplate>
<td style="height: 16px">
<asp:Label ID="Label1" runat="server" Text="暂无检索记录!" Visible="false"></asp:Label>
</td>
</FooterTemplate>
- protected void rpSearch_ItemDataBound(object sender, RepeaterItemEventArgs e)
- {
- if (e.Item.ItemType==ListItemType.Footer)
- {
- if (rpSearch.Items.Count<=0)
- {
- ((Label)e.Item.FindControl("Label1")).Visible = true;
- }
- }
- }
protected void rpSearch_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType==ListItemType.Footer)
{
if (rpSearch.Items.Count<=0)
{
((Label)e.Item.FindControl("Label1")).Visible = true;
}
}
}
第三种:在DataTable加一行数据.
- if (table.Rows.Count == 0)//或者 repAcctLedger.Items.Count == 0
- {
- DataRow dr = dt.NewRow();
- dr[0] = "无数据";
- dt.Rows.Add(dr);
- }
- repeater1.DataSource = table;
- repeater1.DataBind();