Click here to Skip to main content
12,406,687 members (55,407 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET4
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 3:54am
Updated 7-Mar-13 3:59am
RyanDev214.6K
v2
Comments
ThePhantomUpvoter 7-Mar-13 9:57am
   
Please format your code so that it is readable and then explain what "does not work" means.
ryanb31 7-Mar-13 9:59am
   
What exactly does not work?
richcb 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160730.1 | Last Updated 7 Mar 2013
Copyright © CodeProject, 1999-2016
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