0

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.

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.

2 Answers 2

1

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'. 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>
Sign up to request clarification or add additional context in comments.

1 Comment

Cant believe I forgot I had the SelectCommand otherwise I wouldn't have needed to raise the question
0

Just append a where clause to your SelectCommand.

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.