Monday, 5 December 2011

Binding dropdownlist in asp

protected void ddlload() 

SqlDataAdapter da = new SqlDataAdapter("select regno from student", cn); 
DataTable dt = new DataTable(); 
da.Fill(dt); 
ddl.DataSource = dt; 
ddl.DataTextField = "columnname"; ///  "regno" in the above query
ddl.DataValueField = "columnname"; /// "regno" in the above query
ddl.DataBind(); 
ddl.Items.Insert(0, "Select regno");/// first item like Select
ddl.Items.Insert(ddlcountry.Items.Count, "Others");////last item like others





Call this function in Pageload...........

No comments:

Post a Comment