please anybody to help Dropdownlist selected index problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rocksoft
    New Member
    • Jan 2007
    • 7

    please anybody to help Dropdownlist selected index problem

    Hi

    I am working in asp.net with C# web application, I have used visual studio 2003, i have used dropdownlist
    in my application to populate the data from mysql database, i have got problem while i selected the item from
    dropdownlist, its not selecting correct item i'm selecting from dropdownlist, i have 64 records in my table, but i
    tried to work with upto 15 records it will not giving problem, when the scroll will enable to dropdownlist its
    giving problem, its not selecting the correct record what i'm selecting in dropdownlist, i have used following
    codes to fill dropdown and selected index,

    public DataSet LoadShotTaskCod e()
    {
    cmd = new MySqlCommand("H D_PROC_LOADSHOT TASK",global_co n);
    cmd.CommandType = CommandType.Sto redProcedure;
    adapter = new MySqlDataAdapte r(cmd);
    dataset = new DataSet();
    adapter.Fill(da taset,"hd_tbl_t askcodes");
    return dataset;
    }

    private void FillDropDown()
    {
    Access = new clshome();
    ds = Access.LoadShot TaskCode();
    if(ds.Tables[0].Rows.Count != 0 )
    {
    DropDownList1.D ataTextField = "task_code" ;
    DropDownList1.D ataValueField = "task_descripti on";
    DropDownList1.D ataSource = ds;
    DropDownList1.D ataBind();
    if(DropDownList 1.Items.Count != 0)
    {
    TxtEditTaskCode .Text = ds.Tables[0].Rows[0]["task_code"].ToString();
    TxtEditTaskDesc .Text = ds.Tables[0].Rows[0]["task_descripti on"].ToString();
    }
    }
    else
    {
    DropDownList1.I tems.Clear();
    }
    }

    public MySqlDataReader Select_ShotTask Coes(string tcode)
    {
    MySqlCommand taskcmd = new MySqlCommand("s elect * from hd_tbl_taskcode s where task_code='"+ tcode+"'",globa l_con);
    global_con.Open ();
    MySqlDataReader dr = taskcmd.Execute Reader(CommandB ehavior.CloseCo nnection);
    return dr;
    }

    private void DropDownList1_S electedIndexCha nged(object sender, System.EventArg s e)
    {
    Access = new clshome();
    MySqlDataReader taskdr = Access.Select_S hotTaskCoes(Dro pDownList1.Sele ctedItem.Text);
    if(taskdr.Read( ))
    {
    TxtEditTaskCode .Text = taskdr.GetValue (0).ToString();
    TxtEditTaskDesc .Text = taskdr.GetValue (1).ToString();
    }
    Access.global_c on.Close();
    }


    please anybody help me to slove this problem, advanced Thanks for any reply.

    Thanks.
  • radcaesar
    Recognized Expert Contributor
    • Sep 2006
    • 759

    #2
    Not selecting correct value means ?

    What value you get when make select change in combo ?

    :)

    Comment

    • nmsreddi
      Contributor
      • Jul 2006
      • 366

      #3
      Hello

      what actuaaly your problem ,what happenning when select a value ,by default

      is it going to first value in the list, are you using auto post back property of the

      combobox to true, some times in page postback the values of the combo box

      will not point to the value you have selected instead it goes to to the first value

      in the list ,are you facing the same problem i think.

      actually the problem you specified is unable to understand your requirement

      please try to post with exact requirement

      Comment

      Working...