I'm having problem filling the dropdownlist with data from database in a windows based application.
I know how to do that in ASP.NET, but I can't find a solution in .NET 4.5 windows based.
public void Paraqit_ddListKlasa()
{
DataTable dt = new DataTable();
SqlConnection sqlConn = new SqlConnection(StringKoneksioni.Stringu);
sqlConn.Open();
string SQLstringu = "Select KlasaViti, ID_Klasa from KLASA ";
SqlCommand cmd = new SqlCommand(SQLstringu, sqlConn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
ddListKlasa.DataSource = dt;
ddListKlasa.DataTextField = "KlasaViti";
ddListKlasa.DataValueField = "ID_Klasa";
ddListKlasa.DataBind();
ddListKlasa.Items.Insert(0, new ListItem("--Zgjedh--", "0"));
sqlConn.Close();
}
It is not recognizing the DataTextField and DataValueField