Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET4.0
hi
i am making school website in which i want that when new class add in database then auto fill that class in combobox of student registration form during Form load.
 
here is my code but it doesnot work.
can any body help me that problem?
thanks in advance.
 protected void Page_Load(object sender, EventArgs e)
        {
 
            SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\Final Project\FinalProject\FinalProject\App_Data\Record.mdf;Integrated Security=True;User Instance=True");
            conn.Open();
            SqlCommand sc = new SqlCommand("select ClassName from SchoolClass", conn);
            SqlDataReader reader;
 
            reader = sc.ExecuteReader();
            DataTable dt = new DataTable();
            dt.Columns.Add("ClassName", typeof(string));
        
            dt.Load(reader);
 

            drpclass.SelectedValue = "ClassName";
            drpclass.DataSource = dt;
 
            conn.Close();
 
        }
Posted 7-Mar-13 4:54am
Edited 7-Mar-13 4:59am
(no name)129.8K
v2
Comments
ThePhantomUpvoter at 7-Mar-13 9:57am
   
Please format your code so that it is readable and then explain what "does not work" means.
ryanb31 at 7-Mar-13 9:59am
   
What exactly does not work?
richcb at 7-Mar-13 11:13am
   
If you are using ASP.Net, then you need to call the DataBind() method after setting the datasource. That is the only thing I can see without you providing more details.

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

  Print Answers RSS
0 OriginalGriff 6,055
1 DamithSL 4,621
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,500
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 7 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100