Sir, I need your help in the following topic.
I have a comboBox to fill countries.
Among them, there are two type items, one Default countries and non default.
I have to fill both types in ASC order.
eg:-
This is what I intended:-
Australia
India
UAE as default.
Austria
England
Germany
SouthAfrica
USA as non default.
Please help me in this topic
Loading

Nimit JoshiPosted Oct 11, 2013, 12:08 PM
the database code is here:
create database Earth
use Earth
create table Country (ID int primary key identity (1,1), Name varchar(50))
Take a dropdownlist in webform and the cs code is here:
public partial class WebForm1 : System.Web.UI.Page
{
DataTable dt;
SqlDataAdapter adap;
SqlConnection con = new SqlConnection("YOUR CONNECTION STRING");
protected void Page_Load(object sender, EventArgs e)
{
GetCountry();
}
void GetCountry()
{
DropDownList1.DataSource = Get_Con();
DropDownList1.DataTextField = "Name";
DropDownList1.DataValueField = "ID";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, new ListItem("Australia", "0"));
DropDownList1.Items.Insert(1, new ListItem("India","1"));
}
public DataTable Get_Con()
{
adap = new SqlDataAdapter("Select * from Country order by Name", con);
dt = new DataTable();
adap.Fill(dt);
return dt;
}
}
do it and let me know if you have any problem.
Nimit JoshiPosted Oct 14, 2013, 5:55 AM