Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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> 
share|improve this question
add comment

1 Answer

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"].DefaultValue = User.Identity.Name;
}
share|improve this answer
1  
should be .DefaultValue instead of .Value in the c# code –  lincolnk Oct 5 '10 at 13:50
    
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 Oct 6 '10 at 6:30
    
You can give it a shot by using <asp:Parameter Name="username" Type="String" DefaultValue="<%#User.Identity.Name%>" /> –  Jan Jongboom Oct 6 '10 at 6:51
1  
<%#User.Identity.Name%> unfortunately that doesn't work since Parameter doesn't support DataBinding... –  Wodzu Oct 8 '10 at 8:36
    
Thanks Jan, succeeded in codebehind. It is not necessary to declare a Default Value in .aspx file. Can only add to the codefehind file. protected void Page_Init(object sender, EventArgs e) { SqlDataSource1.InsertParameters["UserName"].DefaultValue = User.Identity.Name; } –  Djordje Miljkovic Feb 17 '12 at 17:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.