Got a simple question, if I have this datalist below that gets populated via a sql database.
How do I write the codebehind to response.write("That account number is invalid!") if no data is returned?
Would I use ItemCreated or ItemDatabound?
Would it be something like (which I know is incorrect):
Code:
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black">
<ItemTemplate>
<br />
Account:
<asp:Label ID="AccountLabel" runat="server" Text='<%# Eval("Account") %>'></asp:Label><br />
Name:
<asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>'></asp:Label><br />
Amount:
<asp:Label ID="AmountLabel" runat="server" Text='<%# Eval("Amount", "{0:C}") %>'></asp:Label><br />
<br />
<asp:HiddenField ID="HFAccount" runat="server" Value='<%# Eval("Account") %>' />
<asp:HiddenField ID="HFName" runat="server" Value='<%# Eval("Name") %>' />
<asp:HiddenField ID="HFAmount" runat="server" Value='<%# Eval("Amount") %>' />
</ItemTemplate>
<FooterStyle BackColor="Tan" />
<SelectedItemStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<AlternatingItemStyle BackColor="PaleGoldenrod" />
<HeaderStyle BackColor="Tan" Font-Bold="True" />
</asp:DataList>
How do I write the codebehind to response.write("That account number is invalid!") if no data is returned?
Would I use ItemCreated or ItemDatabound?
Would it be something like (which I know is incorrect):
Code:
Protected Sub DataList1_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList1.ItemCreated
If DataList1 Is Nothing Then
Response.Write("That Account Number was not found, please check it and try again!")
End If
End Sub