sql query
i am binding country dropdownlist from database ,I want to display india as a first item using sql query
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Nov 23, 2013, 10:35 AM
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Insert_data_confirmation
{
public partial class WebForm6 : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
SqlCommand com;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DropDownList_country.Items.Add(new ListItem("--Select--", "0"));
country2();
country1();
}
}
void country1()
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select * from tab1 where country_name!='india' ";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
DropDownList_country.Items.Add(reader["country_name"].ToString());
}
reader.Close();
con.Close();
}
void country2()
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select * from tab1 where country_name='india' ";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
DropDownList_country.Items.Add(reader["country_name"].ToString());
}
reader.Close();
con.Close();
}
}
}