怎么绑定radio到页面

yao_jingli 2011-06-17 12:46:12
<input type="radio" name="radio" id="radio1" class="selectstyle" value="1" checked="checked" />
<input type="radio" name="radio" id="radio2" class="selectstyle" value="2" />
<input type="radio" name="radio" id="radio3" class="selectstyle" value="3" />
<input type="radio" name="radio" id="radio4" class="selectstyle" value="4" />
现在基本功能都已经实现 但是页面显示的不是我数据库里的值
比如说 用户选择了<input type="radio" name="radio" id="radio3" class="selectstyle" value="3" />
我已经把这个值更新到数据库
但是他下次在修改的时候页面显示的是默认<input type="radio" name="radio" id="radio1" class="selectstyle" value="1" checked="checked" />选中的
怎么样能显示我数据库里<input type="radio" name="radio" id="radio3" class="selectstyle" value="3" />是被选中的

求解 在线等
...全文
98 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yao_jingli 2011-06-17
  • 打赏
  • 举报
回复
是用户进到这个页面的时候就显示该用户以前选的是哪个
  • 打赏
  • 举报
回复
使用RadioButtonList
后台设置其SelectedValue 或者SelectedIndex可解


温馨提示:注意结贴率!
  • 打赏
  • 举报
回复


<asp:Button runat="server" ID="btnTest" Text="测试" OnClick="btnTest_Click" />
<asp:RadioButtonList runat="server" ID="rbnShow">
<asp:ListItem Selected="True" Text="公交" Value="1"></asp:ListItem>
<asp:ListItem Text="地铁" Value="2"></asp:ListItem>
<asp:ListItem Text="私家车" Value="3"></asp:ListItem>
</asp:RadioButtonList>

后置代码:

protected void btnTest_Click(object sender, EventArgs e)
{
rbnShow.SelectedValue = "2";
}

yao_jingli 2011-06-17
  • 打赏
  • 举报
回复
具体 写一下呗 我刚学不懂 谢谢
salim890809 2011-06-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zhangyunhebei 的回复:]

使用RadioButtonList
后台设置其SelectedValue 或者SelectedIndex可解


温馨提示:注意结贴率!
[/Quote]

其实用JS也可以做到,不过那样太麻烦了,还是这个正解!
手可摘星辰 2011-06-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zhangyunhebei 的回复:]
使用RadioButtonList
后台设置其SelectedValue 或者SelectedIndex可解


温馨提示:注意结贴率!
[/Quote]
对的
紫川秀 2011-06-17
  • 打赏
  • 举报
回复
你在页面绑定的时候注意取数据库的值.

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧