I have a problem with selecting the selected object from my list.
I associate a collection of users with a drop down list:
ddlContractors.DataSource = service.GetAllUsers(); ddlContractors.DataTextField = "Name"; ddlContractors.DataValueField = "Id"; ddlContractors.DataBind();
He works. But when I try to get the selected object:
var user = (User)ddlContractors.SelectedItem;
I get:
(User)ddlContractors.SelectedItem Cannot convert type 'System.Web.UI.WebControls.ListItem' to 'GWDSite.GWDService.User'
How can I get an object user from a drop down list? I can change the type of the list control if necessary
- "", "". "SelectedItem" "Id", . User ( )
.
SelectedItem ListItem, listItem i.e.
, , SelectedItem/SelectedValue
, / , , "" / - ( , ).
SelectedValue SelectedItem
-
-, , , .
, , .
ua ( , u shud , )... service.GetAllUsers() a List<User> ( , DataTable Array, ). , ur ddlContractors SelectedIndex? -
List<User>
int index = ddlContractors.SelectedIndex;
, List<User> ddlContractors, ( ) List -
User userObject = userList[index];
Source: https://habr.com/ru/post/1763331/More articles:Silverlight - Binding Listbox ActualWidth to the width of ListboxItem - windows-phone-7Netbeans Include Path Function - phpCenter one character of text vertically? - cssHow to apply the $ (document) .ready function to asynchronously loaded elements? - jqueryHelp installing symfony plugin - phpCakePHP: Insert name and path into CTP files in views and elements - jqueryHow can I get the linux module to load another module? - linuxhow to make the local function only the main one! - c ++UIScrollView Always Animation! - iphoneForcing type php - phpAll Articles