[英]Do Not Display Specified Value From SQL Return In Asp.net WebForm GridView
I have an asp.net
application which has a gridview
of all the users but i don't want the 'Admin' user to be displayed to the users. 我有一个asp.net
应用程序,该应用程序具有所有用户的gridview
,但我不希望向用户显示“管理员”用户。
HTML 的HTML
<asp:GridView ID="tblUsers" runat="server" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlUsers" GridLines="None" Width="15%">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
</Columns>
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
</asp:GridView>
<asp:SqlDataSource ID="SqlUsers" runat="server" ConnectionString="<%$ ConnectionStrings:PaydayLunchConnectionString1 %>" SelectCommand="SELECT [Name] FROM [Users]"></asp:SqlDataSource>
I have no code behind for this at all. 我根本没有任何代码。 Will I need some sort of stored proc or something ad if so how would I write it as stored proc's are not my strong point. 我是否需要某种类型的存储过程或广告,如果是的话,我如何将其编写为存储过程不是我的强项。
You need to add just where cluase to your select command like SELECT [Name] FROM [Users] Where [name] != 'Admin' OR SELECT [Name] FROM [Users] Where [fieldname] != 'Admin'. 您只需要在选择命令中添加位置字符串,例如SELECT [Name] FROM [Users] where [name]!='Admin'或SELECT [Name] FROM [Users] Where [fieldname]!='Admin'。 see below code. 参见下面的代码。
<asp:GridView ID="tblUsers" runat="server" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlUsers" GridLines="None" Width="15%">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
</Columns>
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
</asp:GridView>
<asp:SqlDataSource ID="SqlUsers" runat="server" ConnectionString="<%$ ConnectionStrings:PaydayLunchConnectionString1 %>" SelectCommand="SELECT [Name] FROM [Users] Where [name] != 'Admin'"></asp:SqlDataSource>
Just append a where clause to your SelectCommand. 只需在您的SelectCommand中附加一个where子句即可。
HTML 的HTML
<asp:GridView ID="tblUsers" runat="server" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlUsers" GridLines="None" Width="15%">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
</Columns>
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
</asp:GridView>
<asp:SqlDataSource
ID="SqlUsers"
runat="server"
ConnectionString="<%$ ConnectionStrings:PaydayLunchConnectionString1 %>"
SelectCommand="SELECT [Name] FROM [Users] WHERE [name] <> 'Admin'"></asp:SqlDataSource>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.