3

I am trying to write a generic method that would bind any asp.net UI controls (drop down-list, list box.. etc) Here is how I envision how the method should looks like:

public static void  AnyUIObjectDataBinder(Object anyUIcontrol, int id, string dataTextField, string dataValueField)
{
    anyUIcontrol.DataSource = GetList(id);
    anyUIcontrol.DataTextField = dataTextField;
    anyUIcontrol.DataValueField = dataValueField;
    anyUIcontrol.DataBind();
}

I would love to know if it is possible to have such method that accept any asp.net UI controls and set its binding property?

0

1 Answer 1

4

try as

public static void  AnyUIObjectDataBinder(ListControl anyUIcontrol, int id, string dataTextField, string dataValueField)
{
    anyUIcontrol.DataSource = GetList(id);
    anyUIcontrol.DataTextField = dataTextField;
    anyUIcontrol.DataValueField = dataValueField;
    anyUIcontrol.DataBind();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.