1

i am using Visual Studio 2010 professional and SQL server 2008 R2 express

what i am trying to do is detect who is the logged in user and display their detail in a gridview. the logged in user has used asp.net authentication, i have allowed users to access the page using the login process, they have the "user" role set to allow. the admin account can view all users in the account from a gridview, but i also want a logged in user to see their own details in the members section.

this is shown in the code-behind

Protected Sub Page_Load(sender As Object, e As System.EventArgs)
Session("MemberDetails") = User.Identity.Name
End Sub

this is in the main page

<asp:Gridview>
<Columns>
<asp:BoundField DataField="username" HeaderText="username" />
<$ many more fields here--$>
</Columns>
</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
SelectCommand="SELECT username, salutation, fname, sname, address, suburb, postcode, dayphone FROM member WHERE (username = @username)">
<SelectParameters>
<asp:SessionParameter Name="username" SessionField="MemberDetails" />
</SelectParameters>
</asp:SqlDataSource>

all of it should work but instead i get a blank page.

4

2 回答 2

1

您的 GridView 标签不完整,尤其是DataSourceID="SqlDataSource1"

<asp:Gridview runat="server" ID="gvUsers" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="username" HeaderText="username" />
<$ many more fields here--$>
</Columns>
</asp:GridView>
于 2012-10-07T07:28:02.210 回答
0

这个 vb 代码隐藏解决了我的问题:

Protected Sub SqlDataSource1_Selecting(ByVal sender As Object, ByVal e As SqlDataSourceSelectingEventArgs) Handles SqlDataSource1.Selecting
        e.Command.Parameters(0).Value = Me.User.Identity.Name
    End Sub
于 2012-10-08T01:54:10.427 回答