没什么技术含量,我不会啊,求解答,传值bool的
<asp:RadioButtonList ID="RadioButtonList2" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow">
<asp:ListItem Value="1" Text="否" Selected="True"></asp:ListItem>
<asp:ListItem Value="2" Text="是"></asp:ListItem>
</asp:RadioButtonList>
上面是个单选按钮,就2个值,数据库中分别对应false和true啦。下面连接了数据库后,我要添加和更新,如何进行传值呢,textbox的我才学会,这个真不会啊,也没找到。大神教下,下面给出周围代码。就是PrizetoStop这个是bool型的,该怎么传值啊。如果不是bool型的呢,先教我bool的吧,急用。
cmd = new SqlCommand("insert into Prizes(PrizeNo,PrizeName,PrizePrice,StarQuantity,PrizetoStop) values(@PrizeNo,@prizeName,@PrizePrice,@StarQuantity,@PrizetoStop)", con);
cmd.Parameters.Add("@PrizeNo", SqlDbType.Int);
cmd.Parameters.Add("@PrizeName", SqlDbType.NVarChar);
cmd.Parameters.Add("@PrizePrice", SqlDbType.Int);
cmd.Parameters.Add("@StarQuantity", SqlDbType.NVarChar);
bool PrizetoStop=bool.(RadioButtonList1)//就是这句,我是错的。
cmd.Parameters.Add("@PrizetoStop", SqlDbType.Bit);
cmd.Parameters["@PrizeNo"].Value = TextBox5.Text.Trim();
cmd.Parameters["@PrizeName"].Value = TextBox6.Text.Trim();
cmd.Parameters["@PrizePrice"].Value = TextBox7.Text.Trim();
cmd.Parameters["@StarQuantity"].Value = TextBox8.Text.Trim();
cmd.Parameters["@PrizetoStop"].Value = ??????;
[最优解释]
bool bool PrizetoStop= RadioButtonList1.SelectedValue == "2" ? true : false;
String sql5 = "select PrizetoStop from Prizes where PrizeNo=" + id;
SqlCommand cmd1 = new SqlCommand(sql1, con);
SqlCommand cmd2 = new SqlCommand(sql2, con);
SqlCommand cmd3 = new SqlCommand(sql3, con);
SqlCommand cmd4 = new SqlCommand(sql4, con);
SqlCommand cmd5 = new SqlCommand(sql5, con);
string text1 = cmd1.ExecuteScalar().ToString();
string text2 = cmd2.ExecuteScalar().ToString();
string text3 = cmd3.ExecuteScalar().ToString();
string text4 = cmd4.ExecuteScalar().ToString();
string text5 = cmd5.ExecuteScalar().ToString();
con.Close();
TextBox10.Text = text1;
TextBox11.Text = text2;
TextBox12.Text = text3;
TextBox13.Text = text4;
RadioButtonList1.SelectedValue = PrizetoStop;//这件错的
[其他解释]
RadioButtonList1.SelectedValue =PrizetoStop==true ? "2": "1";