Click here to Skip to main content
15,905,913 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Input string was not in a correct format. I am using drop down list how to convert coding!
I want to get integer value.

Schtype = Convert.ToInt32(cmbSchtype.SelectedItem.Value);
GenerateSingleSchedule(Schtype,Billno,option);
-----------

C#
private void FillSchtype()
        {
            try
            {
                cmbSchtype.DataSource = BillMast.GetSchedulelist(Session["DeptId"].ToString());
                cmbSchtype.DataTextField = "Descr";
                cmbSchtype.DataValueField = "ded_field";
                cmbSchtype.DataBind();
                if(Session["language"].ToString()!="English")
                     cmbSchtype.Items.Insert(0,new ListItem("--தேர்நதெடு--"));
                else
                     cmbSchtype.Items.Insert(0,new ListItem("--Select ScheduleType--"));
            }
            catch(Exception ex) {Response.Write(ex.Message);}
        }
Posted
Comments
ZurdoDev 12-Mar-13 8:16am    
What IS the value?

HI,

the error is here

Quote:
Schtype = Convert.ToInt32(cmbSchtype.SelectedItem.Value);

you are referring "cmbSchtype.SelectedItem.Value", but value is empty or null, because of below statement.
Quote:
if(Session["language"].ToString()!="English")
cmbSchtype.Items.Insert(0,new ListItem("--தேர்நதெடு--"));
else
cmbSchtype.Items.Insert(0,new ListItem("--Select ScheduleType--"));

while creating ListItem object, you are specifying only Text, not the value. So, specify some integer value like below.
C#
if(Session["language"].ToString()!="English")
    cmbSchtype.Items.Insert(0,new ListItem("--தேர்நதெடு--", "0"));
else
    cmbSchtype.Items.Insert(0,new ListItem("--Select ScheduleType--", "1"));


hope it helps.
 
Share this answer
 
Comments
E.F. Nijboer 12-Mar-13 8:35am    
To be honest, I think this is even more accurate than my own answer. +5!
Karthik Harve 12-Mar-13 8:44am    
Thanks a lot Nijboer.!!
Have a look at the TryParse method.
http://msdn.microsoft.com/en-us/library/system.int32.tryparse.aspx[^]

Good luck!
 
Share this answer
 
Comments
CHill60 12-Mar-13 8:25am    
Sorry for the overlap - I took too long to type mine!!
Firstly make sure that cmbSchType actually does have a selected value by checking for cmbSchtype.SelectedIndex >=0

Secondly, if the user selects your first entry then it's going to be text that cannot be converted to an integer so instead of using convert use TryParse ...

C#
if(cmbSchtype.SelectedIdex >=0)   // make sure there is something selected
{
     if (int.TryParsecmbSchtype.SelectedItem.Value, out Schtype)) // make sure it's an int
     {
          GenerateSingleSchedule(Schtype,Billno,option); // NOW you can use it
      }
}
}
 
Share this answer
 
May be it will help you

ListItem itm = new ListItem("--Select--", "0");
cmbSchtype.Items.Insert(0, itm);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900