See if this really suits you. Just make the appropriate changes.
public bool preencheTipo_Usuario(DropDownList dl)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("select ");
sb.AppendLine("codtipo, descricao_tipo");
sb.AppendLine("from tbl_tipo_usuario ");
SqlConnection conexao = new SqlConnection();
conexao.ConnectionString = ConfigurationManager.ConnectionStrings["conectDarf"].ConnectionString;
this.cmd = new SqlCommand(sb.ToString(), conexao);
try
{
conexao.Open();
cmd.ExecuteNonQuery();
SqlDataReader dr = cmd.ExecuteReader();
dl.DataSource = dr;
dl.DataTextField = "descricao_tipo";
dl.DataValueField = "codtipo";
dl.DataBind();
dl.Items.Insert(0, new ListItem("--- SELECIONE ---", "-1"));
}
catch (Exception excecao)
{
Erro = excecao.Message;
return false;
}
finally
{
conexao.Close();
}
return true;
}
Exchange Webcontrol for System.Web.UI.WebControls.Dropdownlist
– Caique C.