简体   繁体   中英

how to view specific row on Gridview?

Currently my gridview shows all registered users of my game, when anyone logs in. i would like it to just show the row of user who has just logged, specified by their username. here is the problem, so as the user Nick is currently logged in it should just show the row where username = Nick. How can i do this?

  <asp:SqlDataSource ID="SqlDataSource_Game" runat="server" ConnectionString="<%$ ConnectionStrings:\\MAC\HOME\DESKTOP\NIMV1.MDFConnectionString %>" SelectCommand="SELECT [UserName], [Won], [Lost], [Played] FROM [Table]"></asp:SqlDataSource>
    <br />
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="UserName" DataSourceID="SqlDataSource_Game">
        <Columns>
            <asp:BoundField DataField="UserName" HeaderText="UserName" ReadOnly="True" SortExpression="UserName" />
            <asp:BoundField DataField="Won" HeaderText="Won" SortExpression="Won" />
            <asp:BoundField DataField="Lost" HeaderText="Lost" SortExpression="Lost" />
            <asp:BoundField DataField="Played" HeaderText="Played" SortExpression="Played" />
        </Columns>
    </asp:GridView>

在此处输入图片说明

You need to maintain login-status whenever user logged in loggedout

  1. Add a column as loginStatus
  2. When user logged in set col loginStatus = 1
  3. When user logout set col loginStatus = 0

On pageload where you bind gridview make a query like

Select * from tableName where loginStatus=1

You can directly hide all the unnecessary rows, checking on the fly for the one to show. I mean something like (in a kind of pseudocode, some typos possible):

foreach (DataGridViewRow myrow in GridView1.Rows)
{
    myrow.Visible=false;
    if(myrow.Cells[0].Value == "Nick")
    {
        myrow.Visible=true;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM