parthiban karnan

parthiban karnan

  • NA
  • 549
  • 99.8k

column value bind twice in dropdownlist..

Apr 24 2013 7:25 AM
column value bind twice in dropdownlist..

binded a dropdowlist[continents] with gridview.. but continents appear twice in dropdownlist..

ex: asia asia


        DropDownList1.AppendDataBoundItems = true;
        //  String strConnString = ConfigurationManager
        //    .ConnectionStrings["conString"].ConnectionString;
        String strQuery = "select ID, ContinentName from Continents";
        SqlConnection con = new SqlConnection(str);
        SqlCommand cmd = new SqlCommand();
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = strQuery;
        cmd.Connection = con;
        try
        {
            con.Open();
            DropDownList1.DataSource = cmd.ExecuteReader();
            DropDownList1.DataTextField = "ContinentName";
            //DropDownList1.DataValueField = "Id";
            DropDownList1.DataBind();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            con.Close();
            con.Dispose();
        }
    }




    protected void Button1_Click1(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(str);
        SqlCommand cmd = new SqlCommand("select * from NEWS where CONTINENT = '" + DropDownList1.SelectedValue + "'", con);
        SqlDataAdapter Adpt = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        Adpt.Fill(dt);
        GridView1.DataSource = dt;
        GridView1.DataBind();
        Label1.Text = "record found";





Answers (1)