看看老外都没有解决的问题
以下内容来自网址:http://forums.asp.net/959573/ShowPost.aspx
==========================
问题:
==========================
SqlDatasource parameter question
In SqlDataSource you can have several types of in parameters.
Control Parameter
QueryString Parameter
Form Parameter
Session Parameter
Cookie Parameter
Profile Parameter
My problem is I want my SqlDataSource to use the current logged in users Guid as the parameter for my Source.
I have solved this by Creating a Label control and assining the guid to this label and then using the control parameter for my SqlDataSource.
It works but it seems like a very akward way of doing this.
I have googled a couple of days in search for a good solution but I can't find it. Is there any way of using MemberShip.GetUser().ProviderUserKey
as the in parameter for a Datasource
回答:
===================================================================
Re: SqlDatasource parameter question
You can do something like this,
<SelectParameters>
<asp:Paramter Name=userGuid type="string" />
</SelectParameters>
with your sqlDataSource_selecting event
e.Command.Parameters("@userGuid").Value = MemberShip.GetUser().ProviderUserKey
解决:
==============================
Re: SqlDatasource parameter question
Thanks a lot. That worked very good.
Strange there isn't a default guid parameter to datasources as I would guess this is a very common situation.
A user put something into the database and you would like to show this for him next time he is logged in.
=====
但是:
=====
这个解决方法在asp.net2005express英文正式版中并不能用,出错提示如下:
Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: Input string was not in a correct format.
=====