DropDownList邦定问题
public void dbBind()
{
string conn = "Server=Z-EBAND; uid=sa;Pwd=;Database=UFDATA_600_2007 ";
SqlConnection mycon = new SqlConnection(conn);
string str = "select cVCName from VendorClass ";
SqlDataAdapter da = new SqlDataAdapter(str,mycon);
DataSet ds = new DataSet();
da.Fill(ds, "VendorClass ");
DropDownList1.DataSource = ds.Tables[ "VendorClass "].DefaultView;
DropDownList1.DataTextField = ds.Tables[ "VendorClass "].Columns[0].ToString();
DropDownList1.DataBind();
}
象上边邦定一个DropDownList1用于显示字段 "名称 "怎样把与cVCName(名称)相对应的cVCCode(编号)添加到数据库中
------解决方案--------------------DropDownList1.SelectedValue
------解决方案--------------------DropDownList1.DataSource = ds.Tables[ "VendorClass "];
DropDownList1.DataTextField = "cVCName ";
DropDownList1.DataValueField= "cVCCode ";
DropDownList1.DataBind();
取值 DropDownList1.SelectedValue