How to programmatically set parameters for EntityDataSource and DetailsView?

I'm stumped!

What is the best way to programmatically set a select option for a control EntityDataSource?

In particular, I want to use the Page.User.ProviderUserKey file to get an entry in the user table of user information that I have for the DetailsView element.

I saw the code using asp:ControlParameterto pull the value from the control, but it almost seems like a hack for my situation. I do not need an additional control to set the parameter value.

Any ideas? Thanks in advance!

+3
source share
2

, :

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

- , .

+1

:

<my:CustomParameter Name="MyParam" />

, , Fredrik Normén. , , ScottGu.

:

public class CustomParameter : Parameter
{
    protected override object Evaluate(HttpContext context, Control control)
    {
        // This is where you would grab and return
        // the Page.User.ProviderUserKey value
        return string.Empty;
    }
}
+1

Source: https://habr.com/ru/post/1711420/


All Articles