Click here to Skip to main content
15,063,239 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi pals,am filling a combobox with items from a method on event select index changed but i get the error input string was not in correct format and it cannot populate the tectbox,
here is my code
C#
protected void StudentNameCombobox_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            ManageStudents manageStudents = new ManageStdents(WebUtility.GetConnectionString);

            int StudentId =int.Parse(StudentNameCombobox.SelectedValue.ToString());
            var query =manageStudents.GetStudentsByStudentId(studentId);
            foreach (Students students in query)
            {
                Source3 nestudents = new Source3();
                newStudents.student = (students.StydentId).ToString();
                StudentIdCombobox.DataSource=manageStudents.GetStudentsByStudentId(StudentId);
                studentIdCombobox.DataTextField = "StudentId";
                studentIdCombobox.DataBind();
            }


The combobox does not pick the students added by that particular studentId,,
Source3 is a class which contains newStudents by Get n set which is a string
Posted
Updated 6-Dec-13 7:37am
v2
Comments
Karthik_Mahalingam 6-Dec-13 13:39pm
   
keep break point and check, in which line you are getting cast error ??
BillWoodruff 7-Dec-13 1:41am
   
If this is a problem with Telerik Controls, why not ask a question on their support forums ?
Member 10398773 7-Dec-13 3:38am
   
not a problem of telerik ,,,,

Hi
Try like this,

you wont get the error but it will check for the valid selected id.

if the selected student id is valid, it will execute the rest of code, else it will come out of the check condition.



C#
int StudentId = 0;
            if (int.TryParse(StudentNameCombobox.SelectedValue + "", out StudentId))
            {
                var query = manageStudents.GetStudentsByStudentId(studentId);
                foreach (Students students in query)
                {
                    Source3 nestudents = new Source3();
                    newStudents.student = (students.StydentId).ToString();
                    StudentIdCombobox.DataSource = manageStudents.GetStudentsByStudentId(StudentId);
                    studentIdCombobox.DataTextField = "StudentId";
                    studentIdCombobox.DataBind();
                }
            }
   
I suspect what it means is that your selected value is not a valid integer value. When debugging check what the selected value actually is. Using int.TryParse() is a better way because it doesn't throw exceptions, it returns a bool if successful and an out parameter has the value if successful.
   

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