DropDown List Issue

Sep 13 2016 2:14 AM
Hello Good Morning All
 
I am facing a problem while am fetching the data from database in drop down list then i want to store that selected data in another database.
 
am making a online test
there are different dropdown lists
all lists are getting the data dynamically from databse
when dropdown list sleect the value from databse that selected value i want to store in another table
but am facing the the problem while i am storing the data in another table the value of datavaluefield not saving only name of the column is saving in database my code is showing below
 
plz help me as soon as possible 
 
 
 
 
{
string conn = ConfigurationManager.ConnectionStrings["abc"].ConnectionString;
SqlConnection con = new SqlConnection(conn);
con.Open();
SqlCommand cmd = new SqlCommand("select id,testcategoryname from TestCategoryName", con);
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
DropDownList1.DataSource = cmd.ExecuteReader();
 DropDownList1.DataTextField = "testcategoryname";
DropDownList1.DataValueField = "id";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, new ListItem("--Select Category--", "0"));
 }
{
string conn1 = ConfigurationManager.ConnectionStrings["abc"].ConnectionString;
SqlConnection con1 = new SqlConnection(conn1);
SqlCommand cmd1 = new SqlCommand("select id,testsubcategoryname from TestSubCategoryName");
cmd1.CommandType = CommandType.Text;
cmd1.Connection = con1;
con1.Open();
DropDownList2.DataSource = cmd1.ExecuteReader();
DropDownList2.DataTextField = "testsubcategoryname";
DropDownList2.DataValueField = "id";
DropDownList2.DataBind();
DropDownList2.Items.Insert(0, new ListItem("--Select Sub Category--", "NA"));
}
{
string conn2 = ConfigurationManager.ConnectionStrings["abc"].ConnectionString;
SqlConnection con2 = new SqlConnection(conn2);
SqlCommand cmd2 = new SqlCommand("select id,testquestiontype from TestQuestionType ");
cmd2.CommandType = CommandType.Text;
cmd2.Connection = con2;
con2.Open();
DropDownList3.DataSource = cmd2.ExecuteReader();
DropDownList3.DataTextField = "testquestiontype";
DropDownList3.DataValueField = "id";
DropDownList3.DataBind();
DropDownList3.Items.Insert(0, new ListItem("--Select Question Tye--", "NA"));
}
 }
 
protected void Button2_Click1(object sender, EventArgs e)
{
 DropDownList1.DataValueField);
 string conn4 = ConfigurationManager.ConnectionStrings["abc"].ConnectionString;
SqlConnection con4 = new SqlConnection(conn4);
con4.Open();
SqlCommand cmd4 = new SqlCommand("insert into AddQuestions(testcategory,subcategory,questiontype) values(@testcategory,@subcategory,@questiontype)", con4);
 DropDownList1.DataValueField = Request.QueryString["testcategory"];
 
cmd4.Parameters.AddWithValue("@subcategory", DropDownList2.DataValueField);
cmd4.Parameters.AddWithValue("@questiontype", DropDownList3.DataValueField);
 
  
cmd4.ExecuteNonQuery();
con4.Close();
Response.Redirect("AddQuestions.aspx");
}
 

Answers (2)