views:

33

answers:

1

For SqlDataSource I can configure the external source for the incoming paramater. For example it might be a QueryString, Session, Profile and so on. However I do not have an option to use User as a source.

I know that I could provide value for the parameter in Inserting,Selecting,Updating,Deleting events. But I do not think that this is an ellegant solution because I have some parameteres already definied in aspx file. I do not want to have parameters defined in two separate places. It makes mess.

So can I somehow define this parameter in .aspx file?

    <SelectParameters>
        <asp:QueryStringParameter DefaultValue="-1" Name="ID" 
            QueryStringField="ID" />
        //User.Identity.Name goes here as a value for another parameter  
    </SelectParameters> 
+2  A: 

Declare it in your .aspx and fill it in your codebehind:

aspx

<asp:Parameter Name="username" Type="String" DefaultValue="Anonymous" />

codebehind

protected void Page_Init(object sender, EventArgs e) {
    DataSource.SelectParameters["username"].Value = User.Identity.Name;
}
Jan Jongboom
should be `.DefaultValue` instead of `.Value` in the c# code
lincolnk
Thanks Jan, but this is what I would like to avoid. In yuour example I need to fill value of parameter in codebehind. So I have to handle parameters in two separate places: in aspx file and in cs file. Can't I declare the parameter in aspx and bind value for it in aspx too?
Wodzu
You can give it a shot by using `<asp:Parameter Name="username" Type="String" DefaultValue="<%#User.Identity.Name%>" />`
Jan Jongboom
<%#User.Identity.Name%> unfortunately that doesn't work since Parameter doesn't support DataBinding...
Wodzu