checkboxlist绑定 默认取值

tyrcui 2010-09-29 07:13:48
checkboxlist 多选 值已经写进数据库了
在编辑页面 我想数据库里有的选项默认选中

从数据库中读出的值是List<>出来的,一定要循环吗?
给个代码!

*************
所有项
*************
colproduct_type.DataTextField = "ps_name";
colproduct_type.DataValueField = "ps_id";
colproduct_type.DataSource = ServiceLocator.productsortservice.ProductSortSelectByParentId("0");
colproduct_type.DataBind();
*************
默认项
*************
List<ProductType> colProductType=....
...全文
106 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
tyrcui 2010-09-29
  • 打赏
  • 举报
回复
List<string> 感谢这句话
tyrcui 2010-09-29
  • 打赏
  • 举报
回复
明白了 我试试
一切为了你 2010-09-29
  • 打赏
  • 举报
回复
路过.....................
tyrcui 2010-09-29
  • 打赏
  • 举报
回复
参数“1”: 无法从“string”转换为“WuLuHeWeb.Model.ArticleTagOrderMethod”
wuyq11 2010-09-29
  • 打赏
  • 举报
回复
List<string> colProductType=new List<string>();
foreach (ListItem lst in this.checkboxlist1.Items)
{
if(colProductType.Contains(lst.Value))
lst.Selected =true ;
}

List<ProductType> colProductType=ServiceLocator.productsortservice.ProductSortSelectByParentId("0");
遍历
ProductType p=list.Find(delegate(ProductType x)
{
return x.Name.Equals(lst.Value);
});
if(p!=null) lst.Selected =true ;

forerach(ProductType p in colProductType)
{}
遍历查询
tyrcui 2010-09-29
  • 打赏
  • 举报
回复
colProductType.Contains(colproduct_type.Items[i].Value
前面是个集合 后面是个string contains有用吗?
wuyq11 2010-09-29
  • 打赏
  • 举报
回复
List<ProductType>=ServiceLocator.productsortservice.ProductSortSelectByParentId("0");
foreach (ListItem lst in this.checkboxlist1.Items)
{
if(colProductType.Contains(lst.Value))
lst.Selected =true ;
}
q107770540 2010-09-29
  • 打赏
  • 举报
回复
List<string> colProductType = new List<string>();
for (int i = 0; i < colproduct_type.Items.Count; i++)
{
if (colProductType.Contains(colproduct_type.Items[i].Value))
{
colproduct_type.Items[i].Selected = true;
}
}

62,263

社区成员

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

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

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

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