Thursday, January 13, 2011

Set dorpdown list 0 index position-------- "Select"----------

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["abc"].ToString());
  protected void Page_Load(object sender, EventArgs e)
  {
      con.Open();
      string query = "select * from FilterGridViewBySection ";
      SqlCommand cmd = new SqlCommand(query, con);
      SqlDataAdapter da = new SqlDataAdapter(cmd);
      DataSet ds = new DataSet();
      da.Fill(ds);
      DropDownList1.DataSource = ds;
      DropDownList1.DataTextField = "bid";
      DropDownList1.DataBind();
      //this line create a new item and set it at 0 index position
      DropDownList1.Items.Insert(0, new ListItem("Select", "select"));

  }

No comments:

SQL Optimization

  SQL Optimization  1. Add where on your query  2. If you remove some data after the data return then remove the remove condition in the sel...