I need to automatically set the 'selected' attribute for the correct value in a dropdownlist. I'm not very familiar with this code b/c I didn't write it.
Anyway, here's the code that populates the dropdownlist...it works just fine:
And on the page load, it binds this to the ddl:
And to automatically select the correct item from the ddl, I'm think I would use something like this...I just don't know where to put it.
Any ideas? Not sure if this is enough info to go on or not.
Anyway, here's the code that populates the dropdownlist...it works just fine:
Code:
public static DataSet GetClosuresBillingAddressDataSet(string CustomerId)
{
try
{
DataSet ds = new DataSet();
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.AppendLine("SELECT a.*, b.bill_to_location_id FROM V_CSIDIRECT_BILL_TO a, V_CSIDIRECT_SHIP_TO b ");
sb.AppendLine("WHERE a.location_id = b.bill_to_location_id ");
sb.AppendLine("AND a.CUSTOMER_NUMBER = " + CustomerId + " ");
//TODO - US OR MEXICO
sb.AppendLine("AND a.OPERATING_UNIT = 2008 ");
sb.AppendLine("ORDER BY a.ADDR, a.STATE, a.CITY ");
ds = m_DataWarehouseDatabase.ExecuteDataSet(CommandType.Text, sb.ToString());
//try to get non NA_GDW value because can be US or non-US address
foreach (DataRow dr in ds.Tables[0].Rows)
{
dr[3] = dr[3].ToString().Replace("NA_GDW,", "");
}
return ds;
}
catch (Exception ex)
{
throw ex;
}
}
And on the page load, it binds this to the ddl:
Code:
DataSet dsBilling = ClosuresSystem.GetClosuresBillingAddressDataSet(Session["CUST_ID"].ToString());
ddlBillToAddress.Visible = true;
ddlBillToAddress.DataSource = dsBilling;
ddlBillToAddress.DataBind();
And to automatically select the correct item from the ddl, I'm think I would use something like this...I just don't know where to put it.
Code:
ddlBillToAddress.SelectedIndex == ddlBillToAddress.Items.IndexOf(ddlBillToAddress.Items.FindByValue("bill_to_location_id"))