我做了一个CheckboxList,它不会排队.我没有看到任何方法来控制生成的HTML.现在,由于<td>每个复选框标签的宽度是自动宽度,因此复选框不对齐.如何设置此宽度并使所有标签和复选框显示在两个垂直对齐的列中?
我的代码很简单:
<div style="text-align: center;">
<p>
Here you will tell..
</p>
<asp:CheckBoxList runat="server" ID="cbl" Width="300px"></asp:CheckBoxList>
<br />
<input type="button" id="next_3" value="Next Page" />
</div>
Run Code Online (Sandbox Code Playgroud)
这是一个截屏
alt text http://img718.imageshack.us/img718/6824/checkboxlist.png
我试图在yii框架中使用复选框列表来解决问题.
示例:使用下拉列表,我可以
<?php echo $form->dropdownlist($model,'fathercattle',array(1=>Yours,2=>Mine,3=>Nobody)); ?>
Run Code Online (Sandbox Code Playgroud)
如何使用Yii复选框列表选项获得类似的效果?这些值将作为数组存储在数据库字段中并在数据库中检索?
其次,我如何格式化它?
我知道我可以遍历一个checkboxlist.Items并查看是否没有选中它们,但是在后面的代码中是否有更好的方法来确定是否没有选择任何项目?
我已经提到了这个问题,以了解如何checkbox在数据库中发布所选的值.
但是,由于a (参见下面的快照),我无法获得我的selected值.debugNullReferenceException
这是我的代码:
Model:
public class ProductModel
{
public string ProductId { get; set; }
public string ProductName { get; set; }
public bool Selected { get; set; }
public string[] CheckedColumn { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
View:
@model IEnumerable<DemoApp.Models.ViewModels.ProductModel>
@{
ViewBag.Title = "CheckView";
}
<table>
<tr>
<th>
ProductId
</th>
<th>
ProductName
</th>
<th>
Selected
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.ProductId)
</td>
<td> …Run Code Online (Sandbox Code Playgroud) 如何将CheckBoxList绑定到通用列表对象.此示例代码应该用于此目的:
protected void Page_Load(object sender, EventArgs e)
{
// Works well with the datatable as a data source
//DataTable _entityList = new DataTable();
//_entityList.Columns.Add("Id", typeof(int));
//_entityList.Columns.Add("ProductName", typeof(string));
//_entityList.Rows.Add(new object[] { 1, "First" });
//_entityList.Rows.Add(new object[] { 2, "Second" });
// Doesn't work with the generic list as a data source
List<MyProduct> _entityList = new List<MyProduct>();
_entityList.Add(new MyProduct(1, "First"));
_entityList.Add(new MyProduct(2, "Second"));
cblProducts.DataSource = _entityList;
cblProducts.DataTextField = "ProductName";
cblProducts.DataValueField = "Id";
cblProducts.DataBind();
}
public class MyProduct
{
public int Id;
public …Run Code Online (Sandbox Code Playgroud) 我有CheckBoxList一些项目,当用户点击按钮时,我希望将选中的文本框的值添加到单个字符串中.我一直在这里寻找答案,但大多数都不起作用或产生不良结果.这是我到目前为止的代码:
string selectedItems = CheckBoxList1.Items.???
Run Code Online (Sandbox Code Playgroud)
不知道从哪里开始.任何帮助表示赞赏!
当我选中复选框列表中的复选框时,checkbox.text将添加到列表框中.但是当我取消选中该复选框时,checkbox.text将从列表框中删除.但问题是我不知道如何从列表框中删除所选项目.
![[按此处查看图片] [2] <br>](https://i.stack.imgur.com/HKpta.png)
例如,当我选中checkbox1,checkbox2,checkbox3时,列表框将显示
checkbox1 checkbox2 checkbox3
但是,当我取消选中复选框时,我仍然坚持在这里.救命 !!
这是我的代码:
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked) listBox1.Items.Add(checkBox1.Text);
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
if (checkBox2.Checked) listBox1.Items.Add(checkBox2.Text);
}
private void checkBox3_CheckedChanged(object sender, EventArgs e)
{
if (checkBox3.Checked) listBox1.Items.Add(checkBox3.Text);
}
private void checkBox4_CheckedChanged(object sender, EventArgs e)
{
if (checkBox4.Checked) listBox1.Items.Add(checkBox4.Text);
}
Run Code Online (Sandbox Code Playgroud)