爱好有3个,我写3个check控件
1.<asp:checkbox runat=“serve” ID=“book” text=“书籍”/>
2.<asp:checkbox runat=“serve” ID=“sport” text=“运动”/>
3.<asp:checkbox runat=“serve” ID=“game” text=“游戏”/>
想用sql=“insert into 表 where value()”来获取text里面的内容(就是我选书籍,数据库就会出现书籍,我选游戏,运动,数据库里面就会有游戏,运动)
![](https://profile-avatar.csdnimg.cn/4100f38f100e4111bf7ba2997cc451bd_weixin_63302558.jpg!4)
asp.net中数据库如何获得checkbox控件里面的text的内容
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
3条回答 默认 最新
- CSDN专家-showbo 2021-11-19 23:56关注
如果只能选一个,题主应该用RadioButtonList控件,而不是checkbox,CheckBox是复选框可以多选。
<%@ Page Language="C#" AutoEventWireup="true" %> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { } protected void button1_Click(object sender, EventArgs e) { string value = ""; if (book.Checked) value =book.Text; else if (sport.Checked) value =sport.Text; else if (game.Checked) value =game.Text; //radiobutton用下面的代码 //value = rb.SelectedValue; string sql = "insert into 表(表中的字段)values('"+value+"')"; Response.Write(sql); //执行sql语句的代码 } </script> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> </head> <body> <form id="form1" runat="server"> <asp:RadioButtonList ID="rb" runat="server"> <asp:ListItem Value="书籍">书籍</asp:ListItem> <asp:ListItem Value="运动">运动</asp:ListItem> <asp:ListItem Value="游戏">游戏</asp:ListItem> </asp:RadioButtonList> <asp:checkbox runat="server" ID="book" text="书籍"/> <asp:checkbox runat="server" ID="sport" text="运动"/> <asp:checkbox runat="server" ID="game" text="游戏"/> <asp:Button runat="server" Text="提交" OnClick="button1_Click" ID="button1" /> </form> </body> </html>
有帮助麻烦点下【采纳该答案】,谢谢~~有其他问题可以继续交流~
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥15 metadata提取的PDF元数据,如何转换为一个Excel
- ¥15 关于arduino编程toCharArray()函数的使用
- ¥100 vc++混合CEF采用CLR方式编译报错
- ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
- ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
- ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
- ¥50 如何openEuler 22.03上安装配置drbd
- ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
- ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
- ¥15 Windows11, backspace, enter, space键失灵