Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

--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,

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...