简体   繁体   English

有没有一种方法可以使用LINQ更改单选按钮列表中的“选中”单选按钮?

[英]Is there a way to use LINQ to change the 'checked' radio button in a radio button list?

I have a repeater control that houses several RadioButtonLists with various RadioButtons in each list. 我有一个转发器控件,其中包含几个RadioButtonLists,每个列表中都有各种RadioButtons。 When my page loads I have several different values. 加载页面时,我有几个不同的值。 For the sake of clarity let's say I have values "1", "2", and "3". 为了清楚起见,假设我具有值“ 1”,“ 2”和“ 3”。 I want to have whichever radio buttons in all of the radiobuttonlists that contain that value to be pre-selected. 我希望所有包含该值的单选按钮列表中的任何单选按钮都被预先选择。 I already have the RadioButtonLists I want, I just don't know how to access it further. 我已经有了想要的RadioButtonLists,我只是不知道如何进一步访问它。

Is there a way I can do this in LINQ? 有没有办法可以在LINQ中做到这一点? Something like find the first or default radio button in the radiobuttonlist and checked = true? 像在单选按钮列表中找到第一个或默认单选按钮,然后选中= true?

I was actually over complicating it. 我实际上使它复杂化了。 All you need to do is change the list.SelectedValue equal to whatever values you already have. 您需要做的就是更改list.SelectedValue等于您已经拥有的任何值。

I'm not exactly sure where linq comes into it but you can set the RadioButtonList.SelectedValue property either declaratively or at runtime in the code behind file. 我不确定linq的位置,但是您可以声明性地或在运行时在文件后面的代码中设置RadioButtonList.SelectedValue属性。 This page on MSDN should point you in the right direction: MSDN上的此页面应为您指明正确的方向:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.selectedvalue.aspx http://msdn.microsoft.com/zh-CN/library/system.web.ui.webcontrols.listcontrol.selectedvalue.aspx

Alternatively post your ASPX and ASPX.CS code and I'd be happy to be a bit more specific. 或者,发布您的ASPX和ASPX.CS代码,我很乐意更加具体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM