Repeater
にはアイテムが含まれていないため、HTMLでレンダリングされることはありません。HeaderTemplate
またはFooterTemplate
です。私はそれが空の場合でもクライアント側でそれを操作する必要があります。レンダリング空のリピータ
常にRepeaterをHTMLでレンダリングする方法はありますか?
Repeater
にはアイテムが含まれていないため、HTMLでレンダリングされることはありません。HeaderTemplate
またはFooterTemplate
です。私はそれが空の場合でもクライアント側でそれを操作する必要があります。レンダリング空のリピータ
常にRepeaterをHTMLでレンダリングする方法はありますか?
<FooterTemplate>
には、空のデータテキストを含むラベルを追加し、visibleプロパティをfalseに設定します。今
<FooterTemplate>
<table>
<tr>
<td>
<asp:Label ID="lblEmptyData"
Text="No Data To Display" runat="server" Visible="false">
</asp:Label>
</td>
</tr>
</table>
</FooterTemplate>
リピータを結合しながら、行がそうでない場合は、ラベルが見える何もアクションをしない、その後返さない場合は、データを確認してください。
詳細here。
マークアップでこの
protected bool IsDataEmpty
{
get
{
ICollection list = Repeater1.DataSource as ICollection;
return list.Count == 0 ? true : false;
}
}
をお試しください:@Saurabhが言ったようにLink
は、あなたのメッセージを指定してラベルを追加<FooterTemplate>
を使用する:ステップバイ
<table width="80%">
<tr runat="server"
visible='<%# IsDataEmpty %>'>
<td>
There is no data to display
</td>
</tr>
がリンクをたどりますTextプロパティでvisibleプロパティをfalseに設定します。
<FooterTemplate>
<%-- Label used for showing Error Message --%>
<asp:Label ID="ErrorMessage" runat="server" Text="Sorry!!" Visible="false">
</asp:Label>
</FooterTemplate>
次にコードビハインドでは次のロジックを使用します。データがない場合は、そうでなければ、次のようなデータを示し、メッセージを表示:
protected void Repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
Repeater rpt = sender as Repeater; // Get the Repeater control object.
// If the Repeater contains no data.
if (rpt != null && rpt.Items.Count < 1)
{
if (e.Item.ItemType == ListItemType.Footer)
{
// Show the Error Label (if no data is present).
Label ErrorMessage = e.Item.FindControl("ErrorMessage") as Label;
if (ErrorMessage != null)
{
ErrorMessage.Visible = true;
}
}
}
}
これはより良い、より完全な答えです。 – BritishDeveloper
<asp:Repeater ID="rptList" runat="server" DataSourceID="odsList">
...
<FooterTemplate>
<%if (rptList.Items.Count == 0)
{ %>
**Your message**
<%} %>
</FooterTemplate>
</asp:Repeater>
DataBind()をもう一度呼び出さない限り、 'rptList.Items'はPostBack上では空であると思います。だから警告があります –
'HeaderTemplate'と' FooterTemplate'がまだデータソースがないアイテムを返さない場合でも、レンダリングされるべきです。あなたのケースでは、これらのテンプレートは空白ですか? –