Drop down on selectedindexchanged, always take first value
I created a drop down
populated it dynamically
write a code to display some value based on selectedindexchanged event
but it always takes the first value.
pls help me
code
-------------------------------------------------
// Page Load
protected void Page_Load( object sender, EventArgs e )
{
if (!IsPostBack)
{
PopulateMultipleAddress();
}
}
------------------------------------------------ loading dropdown, it is postback
private void PopulateMultipleAddress()
{
int cid = 0 ;
cid = Convert.ToInt32(DataAccessContext.CustomerRepository.GetIDFromUserName(Membership.GetUser().UserName));
MemberAddress ma = new MemberAddress();
DataSet ds = ma.MemberAddressListing(cid);
if (ds.Tables[0].Rows.Count == 0)
{
uxShippingSelectAddress.Text = "No Multiple Address Found!";
}
else
{
uxShippingSelectAddress.DataSource = ds.Tables[0];
uxShippingSelectAddress.DataTextField = ds.Tables[0].Columns["Address1"].ColumnName.ToString();
uxShippingSelectAddress.DataValueField = ds.Tables[0].Columns["RowID"].ColumnName.ToString();
uxShippingSelectAddress.DataBind();
uxShippingSelectAddress.Items.Insert(0, new ListItem("Select your shipping address"));
uxShippingSelectAddress.SelectedIndex = 0;
}
}
---------------------------------------------- on dropdown selected index change
protected void uxShippingSelectAddress_SelectedIndexChanged(object sender, EventArgs e)
{
PopulateShippingAddressesOnSelect(uxShippingSelectAddress.SelectedIndex);
}
-------------------------------------------
private void PopulateShippingAddressesOnSelect(int rid)
{
if (rid != 0)
{
MemberAddress ma = new MemberAddress();
DataSet ds = ma.MemberAddressListingByRID(rid);
uxShippingFirstName.Text = ds.Tables[0].Columns["FirstName"].ColumnName.ToString();
uxShippingLastName.Text = ds.Tables[0].Columns["LastName"].ColumnName.ToString();
uxShippingCompany.Text = ds.Tables[0].Columns["Company"].ColumnName.ToString();
uxShippingAddress1.Text = ds.Tables[0].Columns["Address1"].ColumnName.ToString();
uxShippingAddress2.Text = ds.Tables[0].Columns["Address2"].ColumnName.ToString();
uxShippingCity.Text = ds.Tables[0].Columns["City"].ColumnName.ToString();
uxCountryState.CurrentState = ds.Tables[0].Columns["State"].ColumnName.ToString();
uxShippingZip.Text = ds.Tables[0].Columns["Zip"].ColumnName.ToString();
uxCountryState.CurrentCountry = ds.Tables[0].Columns["Country"].ColumnName.ToString();
uxShippingPhone.Text = ds.Tables[0].Columns["Phone"].ColumnName.ToString();
uxShippingFax.Text = ds.Tables[0].Columns["Fax"].ColumnName.ToString();
}
}