I want to just bind the dropdown with DB,I have three rows in mine DB.Instead of adding the column data,In mine dropdown System.Data.DropDown is coming three times y So???
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class FrmSatelliteMain : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection("Data Source=(local);Initial catalog=SatelliteTVonPV;User ID=sandy;Password=sandy");
string Query;
SqlCommand cmd;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind();
}
}
private void Bind()
{
Query = "SELECT * FROM Countries";
cmd = new SqlCommand(Query, conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DropDownLanguages.DataSource = ds;
DropDownLanguages.DataBind();
conn.Close();
}
}
create table Countries(UID integer primary key,country varchar(100))
insert into Countries values(1,'Brazil')
insert into Countries values(2,'China')
insert into Countries values(3,'India')
select * from Countries