DropDownList SelectedIndex won't set

Discussion in 'ASP .Net Web Controls' started by Meagan, Oct 29, 2005.

  1. Meagan

    Meagan Guest

    Hello,

    I am stumped...
    during Page_Load, the dropdownlist gets the right index integer set to it
    but doesn't display the correct item, instead always shows the first item.
    I did "Trace.Write(cmbAvail.SelectedIndex.ToString());" and it returns the
    proper index but then doesn't display properly. It must be something
    simple!

    Thanks!

    Nathan

    void Page_Load(object sender, System.EventArgs e)

    {


    concon = (ClientConnection) Session["dll"];


    if (! Page.IsPostBack)

    {

    DataTable dtAvailList = concon.AvailList();

    cmbAvail.DataSource = dtAvailList;

    cmbAvail.DataTextField =
    dtAvailList.Columns["avTime"].ColumnName.ToString();

    cmbAvail.DataValueField = dtAvailList.Columns["avID"].ColumnName.ToString();

    cmbAvail.DataBind();



    if (Request.Params["id"] != null)

    { ViewState["id"]=Convert.ToInt32(Request.Params["id"]);


    if (Convert.ToInt32(Request.Params["id"]) > 0)

    {





    Client
    client=(Client)concon.FindOutstanding((int)Convert.ToInt32(ViewState["id"]));


    txtName.Text=client.FName;

    txtLastName.Text=client.LName;

    txtStreet.Text=client.Street;

    txtAddress2.Text=client.Street2;

    txtCity.Text=client.City;

    txtZip.Text=client.Zip;

    txtEmail.Text=client.Email;

    txtPhone.Text=client.Phone1;

    txtWorkPh.Text=client.Phone2;

    txtMobilePh.Text=client.Phone3;

    txtNotes.Text=client.Notes;

    Trace.Write("avail1="+ client.Avail1.ToString());

    //av1.SelectedIndex=(string)client.Avail1.ToString();

    cmbAvail.ClearSelection();

    cmbAvail.SelectedIndex =
    cmbAvail.Items.IndexOf(cmbAvail.Items.FindByValue(client.Avail1.ToString()));


    Trace.Write(cmbAvail.SelectedIndex.ToString());

    av2.SelectedIndex=(string)client.Avail2.ToString();

    txtDate1.Text=client.AvailDt1.ToString("d");

    txtDate2.Text=client.AvailDt2.ToString("d");

    ViewState["version"]=client.Version;


    DataSet ds=new DataSet();

    ds=(DataSet)concon.FindClientSub((int)Convert.ToInt32(ViewState["id"]));

    grdPets.DataSource=ds.Tables["ClientSub"];

    grdPets.DataBind();

    }

    }


    }

    }
     
    Meagan, Oct 29, 2005
    #1
    1. Advertising

  2. Meagan

    Meagan Guest

    I did try that and got the same result... so, I am not sure about the page
    rendering and how all those events take place but something must be
    misplaced.

    Thanks again for any help!!

    Nate

    "Stimp" <> wrote in message
    news:...
    > On Sat, 29 Oct 2005 Meagan <> wrote:
    >> Hello,
    >>
    >> I am stumped...
    >> during Page_Load, the dropdownlist gets the right index integer set to it
    >> but doesn't display the correct item, instead always shows the first
    >> item.
    >> I did "Trace.Write(cmbAvail.SelectedIndex.ToString());" and it returns
    >> the
    >> proper index but then doesn't display properly. It must be something
    >> simple!
    >>
    >> Thanks!
    >>
    >> cmbAvail.SelectedIndex =
    >> cmbAvail.Items.IndexOf(cmbAvail.Items.FindByValue(client.Avail1.ToString()));

    >
    > have you tried using SelectedValue instead?
    >
    > e.g. cmbAvail.SelectedValue = client.Avail1.ToString()
    >
    > --
    >
    > "I hear ma train a comin'
    > ... hear freedom comin"
     
    Meagan, Oct 29, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VB Programmer
    Replies:
    1
    Views:
    18,577
    Cliff Harris
    Apr 7, 2004
  2. keithb
    Replies:
    1
    Views:
    12,027
    shauns1
    Nov 1, 2006
  3. Replies:
    1
    Views:
    862
  4. S_K
    Replies:
    5
    Views:
    776
    Eliyahu Goldin
    Nov 14, 2007
  5. set dropdownlist selectedindex in datagrid

    , Feb 25, 2007, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    925
Loading...

Share This Page