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
Code:
protected void Page_Load(object sender, EventArgs e)
{
ddlAdvisor.Items.Clear();
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());
}
}
}
Code:
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("@title",txtTitle.Text);
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);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
waiting your opinions, thanks..