--Using [VS ASP.NET]--
Given a dropdown list box (ddlDevice) filled with a Struct objects [DeviceInfo] as follows:
Given a dropdown list box (ddlDevice) filled with a Struct objects [DeviceInfo] as follows:
Code:
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,