Repeater
에 항목이 없으면 HTML로 렌더링되지 않습니다 (심지어 HeaderTemplate
또는 FooterTemplate
). 비어있는 경우에도 클라이언트 쪽에서 조작해야합니다.빈 중첩 렌더링
항상 HTML로 리피터를 렌더링 할 수있는 방법이 있습니까?
Repeater
에 항목이 없으면 HTML로 렌더링되지 않습니다 (심지어 HeaderTemplate
또는 FooterTemplate
). 비어있는 경우에도 클라이언트 쪽에서 조작해야합니다.빈 중첩 렌더링
항상 HTML로 리피터를 렌더링 할 수있는 방법이 있습니까?
<FooterTemplate>
에는 빈 데이터 텍스트가있는 Label을 추가하고 visible 속성을 false로 설정합니다.
이제 리피터를 바인딩하는 동안 데이터를 확인하십시오. 행이 반환되지 않으면 레이블이 표시되고 그렇지 않으면 아무런 조치도 취하지 않습니다.
자세한 내용 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>
그런 다음 코드 숨김에서 다음 논리를 사용하십시오. 데이터가없는 경우는 true, 그렇지 않은 경우는, 다음과 같은 데이터를 표시, 메시지를 보여
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' 여전히 데이터 소스가 어떤 항목을 반환하지 않는 경우에도 렌더링해야합니다. 귀하의 경우이 템플릿이 비어 있습니까? –