0
我有一個用於註冊的ASP.NET嚮導。 在第1步中,我有幾個控件進入表dbo.Emp。在這個步驟1中,我有兩個DropDownList綁定在不同的表中,名爲dbo.Emptype。如何從數據源中使用DropDownList.SelectedIndex?
然而,當插入表格表dbo.Emp,我收到以下錯誤 -
Insert Error:Error converting data type nvarchar to numeric.
我不知道它控制它告訴它。
但有一個說法這裏 -
cmd.Parameters.AddWithValue("@EmpType",DropDownList1.SelectedIndex);
cmd.Parameters.AddWithValue("@DeptID", DropDownList3.SelectedIndex);
我想那是在的empType項目相關聯的INT值被插入到表。 DropDownList1被綁定到稱爲Dbo.EmpType表(TYPEID(PK-自動增加)|類型) 因此,當用戶落下的是控制和選擇價值,我需要DataValueField(即TYPEID)獲得插入到表。
我該怎麼辦?
這是我的綁定類。
public void dropdowntype()
{
SqlConnection myConn = new SqlConnection(@"Data Source=USER-PC\SQLEXPRESS;Initial Catalog=KKSTech;Integrated Security=True");
SqlCommand myCmd = new SqlCommand(
"SELECT Type, TypeID FROM EmpType", myConn);
myConn.Open();
SqlDataReader myReader3 = myCmd.ExecuteReader();
//Set up the data binding.
Emp_type.DataSource = myReader3;
Emp_type.DataTextField = "Type";
Emp_type.DataValueField = "TypeID";
Emp_type.DataBind();
//Close the connection.
myConn.Close();
myReader3.Close();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!(Page.IsPostBack))
{
dropdownDept();
dropdowntype();
dropdownskills();
}
}
SelectedValue選擇項目..我不需要.. 我需要與項目相關的索引.. – Girish 2012-07-27 13:47:58
親愛的SelectedItem dislplays所選項目。告訴我,你已經綁定你的下拉 – 2012-07-27 13:50:20
什麼是你DropDownList1.TextFeild和DropDownList1.ValueFeild的代碼? – 2012-07-27 13:51:14