Click here to Skip to main content
11,930,048 members (43,796 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET4
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");
           SqlCommand sc = new SqlCommand("select ClassName from SchoolClass", conn);
           SqlDataReader reader;
           reader = sc.ExecuteReader();
           DataTable dt = new DataTable();
           dt.Columns.Add("ClassName", typeof(string));

           drpclass.SelectedValue = "ClassName";
           drpclass.DataSource = dt;
Posted 7-Mar-13 4:54am
Edited 7-Mar-13 4:59am
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
Web04 | 2.8.151126.1 | Last Updated 7 Mar 2013
Copyright © CodeProject, 1999-2015
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