GridView中的“EmptyDataText”标记仅在未找到数据时显示
我有下面的Gridview,它可以工作,还有一个“EmptyDataText”标记,如果在单击submit按钮后从数据库中找不到数据,它应该会在屏幕上显示一条消息。问题是,页面打开时,页面上会显示消息“未找到数据”,但我希望仅当用户输入在数据库中找不到的电子邮件地址时,该消息才会显示。我希望我的解释是正确的,我真的不能用更好的方式来表达这个问题,请帮忙GridView中的“EmptyDataText”标记仅在未找到数据时显示,gridview,emptydatatext,Gridview,Emptydatatext,我有下面的Gridview,它可以工作,还有一个“EmptyDataText”标记,如果在单击submit按钮后从数据库中找不到数据,它应该会在屏幕上显示一条消息。问题是,页面打开时,页面上会显示消息“未找到数据”,但我希望仅当用户输入在数据库中找不到的电子邮件地址时,该消息才会显示。我希望我的解释是正确的,我真的不能用更好的方式来表达这个问题,请帮忙 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="Fals
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID"
DataSourceID="SqlDataSource" EmptyDataText="The data could not be found" CellSpacing="3" CellPadding="4"
GridLines="None" ForeColor="#333333">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
SortExpression="ID">
<ItemStyle Font-Names="Verdana" Font-Size="9pt" />
<HeaderStyle Font-Names="Verdana" Font-Size="10pt" />
</asp:BoundField>
<asp:BoundField DataField="name" HeaderText="Name" SortExpression="name">
<ItemStyle Font-Names="Verdana" Font-Size="9pt" />
<HeaderStyle Font-Names="Verdana" Font-Size="10pt" />
</asp:BoundField>
<asp:BoundField DataField="EmailAddress" HeaderText="Email Address" SortExpression="EmailAddress">
<ItemStyle Font-Names="Verdana" Font-Size="9pt" />
<HeaderStyle Font-Names="Verdana" Font-Size="10pt" />
</asp:BoundField>
<asp:BoundField DataField="Address1" HeaderText="Address1" SortExpression="Address1">
<ItemStyle Font-Names="Verdana" Font-Size="9pt" />
<HeaderStyle Font-Names="Verdana" Font-Size="10pt" />
</asp:BoundField>
<asp:BoundField DataField="Address2" HeaderText="Address2" SortExpression="Address2">
<ItemStyle Font-Names="Verdana" Font-Size="9pt" />
<HeaderStyle Font-Names="Verdana" Font-Size="10pt" />
</asp:BoundField>
<asp:BoundField DataField="city" HeaderText="City" SortExpression="city">
<ItemStyle Font-Names="Verdana" Font-Size="9pt" />
<HeaderStyle Font-Names="Verdana" Font-Size="10pt" />
</asp:BoundField>
<asp:BoundField DataField="PostCode" HeaderText="Post Code" SortExpression="PostCode">
<ItemStyle Font-Names="Verdana" Font-Size="9pt" />
<HeaderStyle Font-Names="Verdana" Font-Size="10pt" />
</asp:BoundField>
</Columns>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<FooterStyle BackColor="#5D7B9D" ForeColor="White" Font-Bold="True" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<EditRowStyle BackColor="#999999" />
</asp:GridView>
这可能很简单,可能与页面刷新方式有关?或者这可能很难。。。
我真的不想在用户输入任何信息之前在屏幕上显示消息
谢谢
我想在gridview中对齐中间的EmptyDataText=no info标记,而不是将其放在页面的默认左侧。在哪里要求用户输入电子邮件地址?您可以删除emptydatatext并使用emptyDatatemplate
<EmptyDataTemplate>
<table border="1px" cellpadding="1px" cellspacing="1" width='100%'>
<tr><td>... </td> </tr>
</table>
</EmptyDataTemplate>
文本输入部分是:
<form id="form1" runat="server">
<div>
<div style="margin-bottom: 15px">
<strong><span style="font-family: Verdana"><span style="font-size: 10pt">Enter email
address:</span></span></strong></div>
<div style="margin-bottom: 15px">
<asp:TextBox ID="txtBox" runat="server" Width="210px" TabIndex="1" MaxLength="50"></asp:TextBox></div>
<asp:Button ID="btn" runat="server" Text="Submit" OnClick="btn_Click" Width="93px" />
<div style="margin-top: 15px">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="txtBox"
Text="Please enter a valid email address" runat="server" Font-Bold="False" Font-Names="Verdana"
Font-Size="10pt" />
</div>
<div style="margin-top: 30px; margin-bottom: 15px">
</div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID"
DataSourceID="SqlDataSource" EmptyDataText="wrong data" CellSpacing="3" CellPadding="4"
GridLines="None" ForeColor="#333333">
如果你有
从浏览器查看源代码时,您将获得
<div>
<table cellspacing="0" rules="all" border="1" id="GridView1" style="border-collapse:collapse;">
<tr class="mytextcenter">
<td>The data could not be found</td>
</tr>
</table>
</div>
您可以很容易地找出需要指定的css。这样做,您可以选择css l将文本设置在中心
<EmptyDataTemplate>
<asp:Label ID="Label1" runat="server" Text="No Data Found"
Font-Bold="True" Font-Size="X-Large" ForeColor="#FF0066"
style="position:absolute;left:400px"></asp:Label>
</EmptyDataTemplate>
您还可以先使Gridview不可见,然后启动任何事件使其可见在开始时使Gridview不可见将在本例中起作用。嗨,亨利,这很容易做到吗?我对这很陌生:是的,您可以在GridView中添加visible=false。add gridview1.visible=true在btn_click的方法中你不可能知道下面这个整天困扰我的问题,你会。。。我有一个EmptyDataText=无信息标签,在输入电子邮件地址后显示,从中找不到任何信息,但我想要的是将其设置为页面的中心,而不是左侧。我有一个有效的属性,但是当我尝试对齐文本时,它显然不是一个有效的属性。请帮忙!您是否尝试将cssClass添加到?