在此代码中,cp.=i 选择单个单选按钮,并且 cp.product= 下拉列表1.我给出的选定项目,但它显示错误。 让任何人告诉,我给DOB的产品提供了哪个代码。
Com_psi cp = new Com_psi();
DAL_psi dp = new DAL_psi();
cp.Psiid = int.Parse(TextBox1.Text);
cp.Name=TextBox2.Text;
cp.DOB = int.Parse(TextBox3.Text);
cp.Sex = RadioButton1.
cp.Mobile = int.Parse(TextBox4.Text);
cp.Address = TextBox5.Text;
cp.Product = DropDownList1.SelectedItem;
cp.Amount = int.Parse(TextBox6.Text);
int result = dp.insertpsi(cp);
public int Psiid { get; set; }
public string Name { get; set; }
public int DOB { get; set; }
public string Sex { get; set; }
public int Mobile { get; set; }
public string Address { get; set; }
public string Product { get; set; }
public int Amount { get; set; }
您可以使用 Conditinal 运算符来检查是否选中了单选按钮。如果选中,则分配"男性" 如果未选中,则可以分配"女性"。
解决方案1:如果RadioButton1
值Male
cp.Sex = (RadioButton1.Checked)?"Male":"FeMale";
解决方案 2:如果RadioButton1
值FeMale
cp.Sex = (RadioButton1.Checked)?"FeMale":"Male";
它等于:
if(RadioButton1.Checked==true)
{
cp.Sex = "Male";
}
else
{
cp.Sex="FeMale";
}
解决方案3:对于下拉列表,您可以使用DropDownList1.SelectedItem.Value
试试这个:
cp.Product = DropDownList1.SelectedItem.Value;