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