Shaitan00 Posted March 30, 2005 Posted March 30, 2005 --Using [VS ASP.NET]-- Given a dropdown list box (ddlDevice) filled with a Struct objects [DeviceInfo] as follows: struct DeviceInfo { public int nDevice_ID; public string sDevice_Short; public string sDevice_Address; public DeviceInfo(int pnDevice_ID, string psDevice_Short, string psDevice_Address) { nDevice_ID = pnDevice_ID; sDevice_Short = psDevice_Short; sDevice_Address = psDevice_Address; } } --- MAIN CODE --- DeviceInfo diInfo = new DeviceInfo(1, "Device1", "Home"); ddlDevice.Items.Add(diInfo.ToString()); [code] Now later on in my code I am trying to retrieve the INTEGER value (nDevice_ID) associated with the selected item in the DropDown Listbox. However everytime I try I get casting errors (cannot cast string as DeviceInfo (.Selecteditem) or cannot cast list item as DeviceInfo (.SelectedValue)) I have tried like int dev = ((DeviceInfo)ddlDevice.SelectedItem).nDevice_ID; int dev = ((DeviceInfo)ddlDevice.SelectedValue).nDevice_ID; ANy help would be appreciated. Thanks, Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.