“空数据文本” GridView 中的标签仅在未找到数据时才显示

发布于 2024-08-08 19:18:17 字数 3621 浏览 7 评论 0原文

我有以下 Gridview (有效)和一个“EmptyDataText”标签,如果单击提交按钮后无法从数据库中找到数据,该标签应该在屏幕上显示一条消息。问题是,页面打开时,页面上会显示消息“未找到数据”,但我希望仅当用户输入在数据库中找不到的电子邮件地址时才显示该消息。我希望我的解释是正确的,我真的无法用更好的方式来表达这个问题,请帮忙!

<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>

这可能很简单,也许与页面刷新的方式有关?或者说可能会非常困难... 我只是不想在用户输入任何信息之前就将消息显示在屏幕上。

谢谢。


我想要将 EmptyDataText="no info" 标签居中(在 gridview 中)对齐,而不是将其放在页面的默认左侧。

I have the following Gridview (which works) and an 'EmptyDataText' tag that should show a message on the screen if the data could not be found from the database after clicking the submit button. The problem is, the message 'no data found' is displayed on the page the moment the page is opened but I want the message to appear only if the user enters an email address which could not be found in the db. I hope I explained it correct, I can't really word this problem in a better way, pleae help!

<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>

This might be something quite simple, maybe something to do with the way the page refreshes? Or it might be quite difficult...
I just don't really want the message to be displayed on the screen even befroe the user has enetered any info.

Thanks.


I'm wanting to align centre (in the gridview) the EmptyDataText="no info" tag rather than it being on the default left of the page.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

つ低調成傷 2024-08-15 19:18:17

文本输入部分为:

<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">

The text input part is:

<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">
︶葆Ⅱㄣ 2024-08-15 19:18:17

您在哪里要求用户输入电子邮件地址?您可以删除空数据文本并使用空数据模板。

<EmptyDataTemplate>
   <table border="1px" cellpadding="1px" cellspacing="1" width='100%'>
            <tr><td>...   </td> </tr>
   </table>
</EmptyDataTemplate>

Where you ask user to input email address? you can remove the emptydatatext and use the emptyDatatemplate.

<EmptyDataTemplate>
   <table border="1px" cellpadding="1px" cellspacing="1" width='100%'>
            <tr><td>...   </td> </tr>
   </table>
</EmptyDataTemplate>
长伴 2024-08-15 19:18:17

如果您

从浏览器查看源代码,您将可以

<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。

if you have

when you view the source from browser, you will get

<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>

you can easily to figure out what css you need to specify.

゛清羽墨安 2024-08-15 19:18:17

这样做,你可以选择 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> 

do like this , you can choose CSS l to set text in centre...

<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> 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文