0

I am creating a large form which re-uses the same dropdown-list of employees multiple times. it is a dynamic dropdown-list which uses a sqldatasource to get the employee list from a sql server db. Is there any way of creating a control or something else which will help me in this situation. I need to be able to change the ID of the control every time I use the dropdown-list. I dont want to keep creating a separate dropdown-list with sqldatasource 15 times in the same form. Any Ideas???

1 Answer 1

2

A user control (.ascx) sounds like exactly what you need.

Check out Walkthrough: Creating Reusable Elements with ASP.NET User Controls

Sign up to request clarification or add additional context in comments.

2 Comments

thanks. I have created a control which is a dynamic dropdown list. how do I access the selected value of the control to insert into db. if it was a normal dropdown list, I would use - 'cmd.Parameters.AddWithValue("@LearnSkills", Dropdownlist1.Text);' but I cant use Dropdownlist1.Text when using a user control.
You need to create a read-only (getter only) property in your user control that will expose the string value of the value selected in the drop down list, like this: public string SelectedValue { get { return dropdownlist1.Text; } }

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.