Mhmt
Mhmt

Reputation: 769

How to convert value of aspx combobox selected item to int?

I know it is very basic but I failed.

public static int devId;
protected void Page_Load(object sender, EventArgs e) { }

It is working ! I set value static

protected void btn2_Click(object sender, EventArgs e)
{
    devId = 325283298;  
}

It is not working !

protected void btn2_Click(object sender, EventArgs e)
{
    devId = int.Parse(cmbDealer.SelectedItem.Value.ToString());
}

<dx:ASPxComboBox ID="cmbDealer" runat="server" TextField="FirmName" 

         ValueField="DeviceID" EnableSynchronization="False"  Width="130" 

         EnableIncrementalFiltering="True"   DataSourceID="lnqDealer1" 

          Theme="Youthful">

</dx:ASPxComboBox>

Upvotes: 0

Views: 1442

Answers (3)

Mhmt
Mhmt

Reputation: 769

Thank you guys !

Solved by

devId=Convert.ToInt32(cmbDealer.SelectedItem.Value.ToString())

Upvotes: 0

Sudhakar Tillapudi
Sudhakar Tillapudi

Reputation: 26199

You can check the SelectedIndex property before converting the value.

if(cmbDealer.SelectedIndex>-1)
devId = Convert.ToInt32(cmbDealer.SelectedItem.ToString());

Upvotes: 1

Govinda Rajbhar
Govinda Rajbhar

Reputation: 3034

You can try below code. if i am not wrong then you want to get the selected value of dropdownn. so you can use below code.

code

devId=Convert.ToInt32(cmbDealer.SelectedValue);

with this code you will get the selected value of dropdown. i hope it will helpful.

Upvotes: 1

Related Questions