首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

没什么技术含量,小弟我不会啊求解答,传值bool的

2012-12-14 
没什么技术含量,我不会啊,求解答,传值bool的asp:RadioButtonList IDRadioButtonList2 runatserver

没什么技术含量,我不会啊,求解答,传值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;

[其他解释]
bool PrizetoStop=RadioButtonList1.SelectValue=="1";
[其他解释]
引用:
C# code



12

   bool bool PrizetoStop= RadioButtonList1.SelectedValue == "2" ? true : false;

多了一个bool吧?还有一个问题如下,这个怎么取值啊,还是这个。
 String sql1 = "select PrizeNo from Prizes where PrizeNo=" + id;
            String sql2 = "select PrizeName from Prizes where PrizeNo=" + id;
            String sql3 = "select PrizePrice from Prizes where PrizeNo=" + id;
            String sql4 = "select StarQuantity from Prizes where PrizeNo=" + id;


            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";

[其他解释]
引用:
C# code



12

RadioButtonList1.SelectedValue =PrizetoStop==true ? "2": "1";

提示我不存在prizetostop,看看我给的代码呢,两部分,这个是编辑的。
[其他解释]
你执行的     
String sql5 = "select PrizetoStop from Prizes where PrizeNo=" + id;
string text5 = cmd5.ExecuteScalar().ToString();
con.Close();
所以  
 RadioButtonList1.SelectedValue = text5==true ? "2": "1";; 
[其他解释]
引用:
你执行的     
String sql5 = "select PrizetoStop from Prizes where PrizeNo=" + id;
string text5 = cmd5.ExecuteScalar().ToString();
con.Close();
所以  
 RadioButtonList1.SelectedValue = text5==true ? "2"……


无法将类型“object”隐式转换为“string”。存在一个显式转换(是否缺少强制转换?)

这个我试过了,你可以换上面的代码
------其他解决方案--------------------


 RadioButtonList1.SelectedValue = text5;直接写
[其他解释]

引用:
RadioButtonList1.SelectedValue = text5;直接写

木有用的,我试过了,关键是上面我又string这个东西,怎么强制转换呢,或者换个方法,你看下我代码啊。
[其他解释]
引用:
bool PrizetoStop=RadioButtonList1.SelectValue=="1";

帮我看看呗,版主。上面那个你的么判断,或许也可以,就是我不会用,帮我看看下面的北,是从数据库中取,注意类型是bit

热点排行