Search code examples
c#asp.netparametersdetailsviewentitydatasource

How to programmatically set parameters for EntityDataSource and DetailsView?


Im stumped!

What is the best way to programmatically set a selecting parameter for the EntityDataSource control?

Specifically, I want to use the Page.User.ProviderUserKey to get a record in a custom User Details table I have, for a DetailsView.

I've seen code using the asp:ControlParameter to pull a value from a control, but that almost seems like a hack for my situation. I don't want an extra control just to set the parameter value.

Any ideas? Thanks in advance!


Solution

  • If creating a custom parameter type feels like too much work, you can programatically add a basic parameter as follows:

    Parameter parameter = new Parameter("MyParam", TypeCode.String,
        Page.User.ProviderUserKey);
    MyDataSource.SelectParameters.Add(parameter);
    

    Something like this should give you what you need.