How to populate a dropdownlist using a stored proc

2019-08-17 03:14发布

问题:

I am working on a webpage that requires distinct user information to be displayed. several different users will be using this page, so the data will be different for each account. I am new to programming maintenance pages so bare with me.

this information is retrieved through stored procedures via entitymodel.

I cannot use an objectdatasource because my SP for the DDL requires an parameter(UserId) (unless there is a way to do it, in which I would not know !) The UserId is grabbed at page load via aspnet membership. this DDL also needs to be populated as the page opens up. I have done some research on programmatically populating a DDL but cannot find any examples that tailor to what I am trying to do.

I need a general DDL to be populated(item and value) by a SP with a parameter(userId), when the page opens up. Nothing more, nothing less :)

My question basically would be; what would be the best way to populate the dropdownlist under these circumstances

回答1:

This post uses a Non-Typed-DataSet and a stored procedure to bind to a CheckBoxList which is the same principle (caveat: own blog post):

http://www.codersbarn.com/post/2008/10/12/Bind-CheckBoxList-to-DataSet.aspx