【发布时间】:2013-10-09 20:52:44
【问题描述】:
这段代码表面上看起来很简单,但我试图在 datalist 中没有记录时显示一条消息。
我在标记上有这个:
<asp:DataList ID="DataList1" runat="server" CellPadding="4"
DataSourceID="SqlDataSource1"
Font-Bold="False" OnSelected="SqlDataSource1_Selected" Font-Names="Verdana"
Font-Size="Small" RepeatColumns="2"
RepeatDirection="Horizontal" Width="100%" ForeColor="#333333">
<AlternatingItemStyle BackColor="White" ForeColor="#284775" />
...
...
</asp:DataList>
<asp:label CssClass="Treb10Blue" ID="lblMsg" runat="server"></asp:Label>
然后在代码隐藏中,我有这个:
Protected Sub SqlDataSource1_Selected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles SqlDataSource1.Selected
If e.AffectedRows = 0 Then
lblMsg.Visible = True
lblMsg.Text = "No records found"
Else
lblMsg.Text = ""
End If
End Sub
我没有收到任何错误,但没有显示消息。
有什么想法可能是错的吗?
【问题讨论】:
-
看看这个question可以帮助你
-
“e.AffectedRows”的值是什么?