A
Andy Sutorius
How do you tell the dropdownlist datatextfield and datavaluefield to be
bound to specific columns using the following code?
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
SqlConnection conn = new
SqlConnection("server=localhost;trusted_connection=yes;database=Test");
SqlCommand cmd = new SqlCommand("SELECT * FROM Dogs", conn);
try
{
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
DropDownList1.DataSource = reader;
DropDownList1.DataTextField = ;
DropDownList1.DataValueField = ;
DropDownList1.DataBind();
}
catch (Exception ex)
{ Response.Write(ex.ToString()); }
finally
{ conn.Dispose(); }
}
}
bound to specific columns using the following code?
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
SqlConnection conn = new
SqlConnection("server=localhost;trusted_connection=yes;database=Test");
SqlCommand cmd = new SqlCommand("SELECT * FROM Dogs", conn);
try
{
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
DropDownList1.DataSource = reader;
DropDownList1.DataTextField = ;
DropDownList1.DataValueField = ;
DropDownList1.DataBind();
}
catch (Exception ex)
{ Response.Write(ex.ToString()); }
finally
{ conn.Dispose(); }
}
}