我正在根据上一页查询字符串上传递的内容构建一个 GridView。
如果未填充 GridView,是否有办法显示“未找到记录”的消息?即查询不产生任何记录来填充GridView。
代码:
<div class="centergrid">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" CssClass="bookgridview">
<Columns>
<asp:TemplateField HeaderText="Choose">
<ItemTemplate>
<asp:HyperLink ID="lnkSelect" runat='server' NavigateUrl='<%# String.Format("~/bookingform.aspx?ID={0}", Eval("ScheduleId")) %>'>Book</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TName" HeaderText="Name" SortExpression="TName" />
<asp:BoundField DataField="SDate" HeaderText="Date" SortExpression="SDate" DataFormatString="{0:d}" />
<asp:BoundField DataField="STime" HeaderText="Time" SortExpression="STime" />
<asp:BoundField DataField="TPriceadult" HeaderText="Price (Adult)"
SortExpression="TPriceadult" DataFormatString="{0:C}" />
<asp:BoundField DataField="TPricesenior" HeaderText="Price (Student/Senior)"
SortExpression="TPricesenior" DataFormatString="{0:C}" />
<asp:BoundField DataField="TPricechild" HeaderText="Price (Child)"
SortExpression="Tpricechild" DataFormatString="{0:C}" />
<asp:BoundField DataField="TDuration" HeaderText="Duration"
SortExpression="TDuration" />
<asp:BoundField DataField="ScheduleId" HeaderText="ScheduleId"
SortExpression="ScheduleId" Visible="False" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ChinatowndbConnString %>"
SelectCommand="SELECT * FROM [vwSchedule] Where TourId=@tid">
<SelectParameters>
<asp:QueryStringParameter DbType="Int32" Name="tid" QueryStringField="tourid" />
</SelectParameters>
</asp:SqlDataSource>