Thread: A problem on dropdownlist selecteditem attributes..

  1. #1
    Registered User Aga^^'s Avatar
    Join Date
    Aug 2008

    Question A problem on dropdownlist selecteditem attributes..

    i have a problem on dropdownlist's selecteditem attributes. On page load part i filled the dropdownlist 's item and attributes ( id,name ). Items are advisor name and surname, attributes are id and name,surname.

    On this page student upload his thesis,the insertion process executes but the advisor's id and name is the last person on the dropdownlist, not the selected one.

    my code is below

    protected void Page_Load(object sender, EventArgs e)
            DataTable dt = DBCodes.DataGetir("SELECT * FROM advisor ORDER BY ad_name ASC");
            for (int i = 0; i < dt.Rows.Count; i++)
                ddlAdvisor.Items.Add(dt.Rows[i]["ad_name"].ToString() + " " + dt.Rows[i]["ad_sname"].ToString());
                for (int j = 0; j < ddlAdvisor.Items.Count; j++)
                    ddlAdvisor.Items[j].Attributes.Add("name", dt.Rows[i]["ad_name"].ToString() + " " + dt.Rows[i]["ad_sname"].ToString());
                    ddlAdvisor.Items[j].Attributes.Add("id", dt.Rows[i]["ad_id"].ToString());
        protected void btnUpload_Click(object sender, EventArgs e)
    SqlConnection con = new SqlConnection();
            con.ConnectionString = ConfigurationManager.ConnectionStrings["DBCon"].ConnectionString;
            SqlCommand cmd = new SqlCommand("INSERT INTO theses (these_lang,these_title,these_up_date,these_subject,these_ad_id,these_ad_name1,these_keywords,these_rest,these_abstract,these_file,stu_no,stu_name,stu_surname,these_state,these_approval) VALUES(@lang,@title,@date,@subject,@adid,@ad1,@keyword,@rest,@abstract,@file,@sno,@sname,@ssname,@state,@approval)", con);
            cmd.Parameters.AddWithValue("@lang", ddlLang.SelectedItem.ToString());
            cmd.Parameters.AddWithValue("@date", DateTime.Now);
            cmd.Parameters.AddWithValue("@subject", "?");
            cmd.Parameters.AddWithValue("@adid", ddlAdvisor.SelectedItem.Attributes["id"]);
            cmd.Parameters.AddWithValue("@ad1", ddlAdvisor.SelectedItem.Attributes["name"].ToString());
            cmd.Parameters.AddWithValue("@keyword", txtKeywords.Text);
            cmd.Parameters.AddWithValue("@rest", ddlRest.SelectedIndex);
            cmd.Parameters.AddWithValue("@abstract", txtAbstract.Text);
            cmd.Parameters.AddWithValue("@file", ".\\theses\\" + fuTheseFile.FileName);
            cmd.Parameters.AddWithValue("@sno", Session["stuno"].ToString());
            cmd.Parameters.AddWithValue("@sname", Session["stuname"].ToString());
            cmd.Parameters.AddWithValue("@ssname", Session["stusname"].ToString());
            cmd.Parameters.AddWithValue("@state", 0);
            cmd.Parameters.AddWithValue("@approval", 0);
    waiting your opinions, thanks..

  2. #2
    Ethernal Noob
    Join Date
    Nov 2001
    To debug, why not assign a delegate to the SelectedIndexChanged, perhaps that is being triggered before you click the button for some reason. I haven't used for some time though, but it seems like if you selected it, it should change the index.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
Website Security Test