Pass UserName to Database
Hello, I didn't get much response on my first posting, so I'm trying again (hopefully being a little clearer)
I want to be able to pass the logged in name from the website to the database for Selecting.
I have spent days and days on this now and I just do not know where else to turn. I have been through topic 40908 MANY times. For some reason it will not pass the parameter to the database.
Any help would be extremely appreciated.
<script runat="server">
protected void MyActivities_Selecting(Object sender, System.Web.UI.WebControls.SqlDataSourceSelectingEv entArgs e)
{
e.Command.Parameters["@UserName"].Value = Membership.GetUser().UserName;
}
</script>
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 1</title>
</head>
<body>
<form id="form1" runat="server">
<asp:LoginName runat="server" id="LoginName1" />
<asp:LoginStatus runat="server" id="LoginStatus1" />
<asp:GridView runat="server" id="GridView1" AutoGenerateColumns="False" DataSourceID="MyActivities">
<Columns>
<asp:boundfield DataField="UserName" SortExpression="UserName" HeaderText="UserName">
</asp:boundfield>
</Columns>
</asp:GridView>
<asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:connectionName %>" ProviderName="<%$ ConnectionStrings:connectionName.ProviderName%>" SelectCommand="SELECT [UserName] FROM [TABLE] WHERE ([UserName] = @UserName)">
<SelectParameters>
<asp:Parameter Type="Object" DefaultValue="test" Name="UserName" />
</SelectParameters>
</asp:SqlDataSource>
</form>
</body>
</html>
Thanks Lee.
|