我正在使用VS 2005,在asp.net中请告诉我如何在项目数量超出指定数量后在checkboxlist中显示滚动条.喜欢我的情况,如果他们在我的复选框列表中存在超过5个项目而不应该显示滚动条..我不想修复它的高度,就好像它们只有1个项目,而不应该只占用1个项目的空间. .. 请帮我...
我已经使用了这个,但是它的占用空间(Hight)甚至是列表中的1或2个项目.. div style ="overflow-y:auto; height:100px"
如何在asp.net的复选框列表中获取所选索引.我应该循环查找是否已选中列表框,或者我可以在不这样做的情况下了解.我想做这个
if(选中Checkboxlist){do this} else {do this}
如何查找是否在asp.net中选中了复选框列表
int roleselected = ckl_EditRole.Items.SelectedIndex;
Run Code Online (Sandbox Code Playgroud) 我正在尝试将类别与产品相关联.到目前为止我实现它的方式是
Class Product
has_many :categorizations
has_many :categories, through: :categorizations
Run Code Online (Sandbox Code Playgroud)
.
Class Categorization
belongs_to :product
belongs_to :category
Run Code Online (Sandbox Code Playgroud)
.
Class Category
has_many :categorizations
has_many :products, through: :categorizations
Run Code Online (Sandbox Code Playgroud)
在我的产品/ _form.html.erb中
<div class="field">
<%= f.label :category_id %><br />
<%= collection_check_boxes(:product, :category_id, Category.all, :id, :name) %>
</div>
Run Code Online (Sandbox Code Playgroud)
我不确定如何正确地做到这一点.
解决方案
变化::category_id对:category_ids,并设置强PARAMS
def product_params
params.require(:product).permit(:title, :description, :price, :category_ids => [])
end
Run Code Online (Sandbox Code Playgroud) 我有一组复选框,其中至少一个必须被选中才能提交表单。为此,我相同地命名每个复选框并设置required属性。
但这不起作用:
<input name="mycheckgroup" type="checkbox" value="1" required />
<input name="mycheckgroup" type="checkbox" value="2" required />
<input name="mycheckgroup" type="checkbox" value="3" required />
Run Code Online (Sandbox Code Playgroud)
我必须选中所有三个框才能提交表单:-(
如果这是单选按钮,它会起作用……但我希望至少选中一个或多个框。
任何人都可以帮忙吗?
使用此处问题中显示的方法,我可以从我的获取所选项目值CheckBoxList:
var selectedCheckBoxItems = from key in Request.Form.AllKeys
where key.Contains(cbl.ID)
select Request.Form.Get(key);
Run Code Online (Sandbox Code Playgroud)
然后我可以迭代结果:
foreach (var item in selectedCheckBoxItems)
{
}
Run Code Online (Sandbox Code Playgroud)
问题是item只是发布的值,对于复选框,它只是字符串"on".
我需要能够通过索引或其他方法确定哪个项目"打开".
问: 我如何确定适合该项目CheckBoxList的选择,使用Request.Form?
这是我的CheckBoxList定义:
<asp:CheckBoxList runat="server" ID="cblAnimalType" SelectionMode="Multiple" DataTextField="OptionText" DataValueField="OptionId" AutoPostBack="True"/>
Run Code Online (Sandbox Code Playgroud)
项目从后面的代码添加到列表中:
DataTable dt = GetData(SqlGetListOptions, paramList);
cbl.DataSource = dt;
cbl.DataBind();
Run Code Online (Sandbox Code Playgroud)
另一个要知道的重要事情是ViewStateMode="Disabled",所以我必须Request.Form用来获取所选项目.
在回复评论时,以下是CheckBoxList的HTML呈现方式:
@Leopard指出他看到HTML中呈现的值在我的情况下没有发生.AdamE对这个问题的回答解释了原因.我在web.config中有以下行:
<pages validateRequest="false" controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
Run Code Online (Sandbox Code Playgroud)
这解释了为什么我看到"开"而不是所选项的实际值.我无法在没有验证它会破坏其他内容的情况下从web.config中提取兼容性,但似乎如果可以安全删除该设置,则可以从代码隐藏中访问复选框列表值.
我正在尝试使用角度材料菜单中的键盘槽复选框列表进行导航,但没有成功。我的代码:
<button [matMenuTriggerFor]="testMenu">Test</button>
<mat-menu #testMenu="matMenu">
<mat-checkbox role="menuitemcheckbox">Option 1</mat-checkbox>
<mat-checkbox>Option 2</mat-checkbox>
<mat-checkbox>Option 3</mat-checkbox>
<mat-checkbox>Option 4</mat-checkbox>
</mat-menu>
Run Code Online (Sandbox Code Playgroud)
当我打开菜单时, mat-menu-panel 得到tabindex="-1". 我试图覆盖它,但没有任何帮助。
角度版本:5.2.9
有人可以帮忙吗?
下面是 react 组件的一部分,其中列出了一个动态复选框:
<div className="pb-4">
<p>Choose the task owner(s):</p>
{
peerIds.map(id => {
if (currentUserId != id)
return (
<label className="checkbox-inline mr-3">
<input onChange={onChange_TaskOwner}
type="checkbox"
name="taskowner"
checked={st_taskOwnersId.filter(function (item) {return (item == id)}).length > 0}
value={peers[id].id} />
<span>{peers[id].fullName}</span>
</label>
)
})
}
<div style={{ clear: 'both' }}></div>
</div>
Run Code Online (Sandbox Code Playgroud)
在上面的代码中checked,如果当前 id 已经在名为st_taskOwnersId.
我使用hook如下存储已检查项目的 Id 。onChange_TaskOwner函数更新st_taskOwnersId取决于它是checked或unchecked:
const [st_taskOwnersId, set_taskOwnersId] = useState([] as any);
const onChange_TaskOwner = (event) => { …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个闪亮的应用程序。在这个特定的应用程序中,我有一组单选按钮,其中选择一个将在下面显示一组选项作为复选框,选择另一个单选按钮将选择其他选项集。请在下面找到 UI 和服务器代码。
library(shiny)
library(shinydashboard)
library(shinyWidgets)
d <-
data.frame(
year = c(1995, 1995, 1995, 1996, 1996, 1996, 1997, 1997, 1997),
Product_Name = c(
"Table",
"Chair",
"Bed",
"Table",
"Chair",
"Bed",
"Table",
"Chair",
"Bed"
),
Product_desc = c("X", "X", "X", "Y", "Y", "Y", "Z", "Z", "Z"),
Cost = c(1, 2, 3, 4, 2, 3, 4, 5, 6)
)
ui <- shinyUI(fluidPage(
useShinydashboard(),
tabPanel(
"Plot",
sidebarLayout(
sidebarPanel(
radioButtons(
"Choose",
"Choose One",
c("Year" = "p", "Numbers" = "l")
),
uiOutput('checkbox'),
#width = 2,
position …Run Code Online (Sandbox Code Playgroud) 我正在开发一个ASP.Net MVC 3 Web应用程序,我最近发布了一个关于如何显示复选框列表的问题
感谢RubbleFord和Darin Dimitrov的帮助,我得到了这个工作.
这适用于一个复选框列表,但是,我现在需要能够在同一个视图上显示多个复选框列表,即查看附加的图像.

我用来当前显示一个列表的ViewModels如下;
public class ViewModelShiftSubSpecialties
{
public ListItem specialtyName { get; set; }
public IEnumerable<ViewModelCheckBox> SubSpecialityList { get; set; }
}
public class ViewModelCheckBox
{
public string Id { get; set; }
public string Name { get; set; }
public bool Checked { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在我的控制器中,我填充了ViewModelShiftSubSpecialties,如下所示:
var subSpecialties = GetSubSpecialtiesForSpecialty(5);
ViewModelShiftSubSpecialties viewModel = new ViewModelShiftSubSpecialties();
var checkBoxList = new List<ViewModelCheckBox>();
viewModel.specialtyName = _listService.GetListItemByID(5); //Medicine Specialty
foreach (var item in …Run Code Online (Sandbox Code Playgroud) 我正在运行一组数据,这将填充CheckBoxList.我想显示列表中的所有项目,但某些项目将被禁用,因为它们不符合条件(其状态等于非活动状态).如何在后面的代码中将项目设置为禁用(Enabled = false)?
if (node.SelectSingleNode("Status") == "Inactive")
{
customerList.Items.Add(new ListItem(displayName, displayValue)); // DISABLED
}
else
{
customerList.Items.Add(new ListItem(displayName, displayValue)); // ENABLED
}
Run Code Online (Sandbox Code Playgroud)