Link to home
Start Free TrialLog in
Avatar of SirReadAlot
SirReadAlot

asked on

DropDownlist control

Morning guys,

I am carrying out an update on a dropdown control with works perfectly.
So when a user selects an item from the dropdown it updates in the
database. But on pageload I what the new selected item to be visible
and not default item on the dropdown.

EXAMPLE.
1)original item on the dropdown is A,
2)the new selected item is B
3)but on pageload it defaults to A, BUT SHOULD BE B.

thanks guys


public void dgCompensation_ItemDataBound(Object Sender, DataGridItemEventArgs e)
            {
   
                  if (e.Item.ItemType == ListItemType.EditItem)
                  {
        
                      DataRowView objDataRowView = (DataRowView)e.Item.DataItem;
                      string currentDeduction = (string)objDataRowView[2].ToString();
                          DropDownList ctlDropDownList = (DropDownList)e.Item.FindControl("DeductDropDownList");
            
                        if (ctlDropDownList != null)
                        {
                              ctlDropDownList.Items.Add("Y");
                              ctlDropDownList.Items.Add("N");
                              ctlDropDownList.Items.Add("E");
                        }
                        ctlDropDownList.SelectedIndex = ctlDropDownList.Items.IndexOf(ctlDropDownList.Items.FindByText(currentDeduction));
                  }
   
            }
      
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SirReadAlot
SirReadAlot

ASKER

will try
string s = "N";
                              ctlDropDownList.Items.Add("Y");
                              ctlDropDownList.Items.Add("N");
                              ctlDropDownList.Items.Add("E");

                              int i = ctlDropDownList.FindControl(s);=========> there is no findcontrol for string
                              ctlDropDownList.SelectedIndex = i;

thanks,

I fink the dropdown should default to whats on the datagrid

thanks