【发布时间】:2012-02-25 22:37:08
【问题描述】:
我在 checkboxlist 中添加了一些自定义属性,但我想知道为什么我无法检索自定义属性的值。这将类似于这篇文章jQuery - find control using custom attribute。但我想要的是通过自动回发和后面的代码检索。
int temp = 0;
foreach (DataRow rows1 in ds_ss_equipments_data.Tables[0].Rows)
{
cblEquip.Items.Add(new ListItem(rows1["name"].ToString() + " " + rows1["quota"].ToString() + " X " + rows1["price"].ToString(), rows1["id"].ToString()));
cblEquip.Items[temp].Attributes["price"] = rows1["price"].ToString();
cblEquip.Items[temp].Attributes["id"] = rows1["id"].ToString();
cblEquip.Items[temp].Attributes["quota"] = rows1["quota"].ToString();
temp += 1;
}
foreach (ListItem li in cblEquip.Items)
{
if (li.Selected)
{
equip += (Convert.ToDecimal(li.Attributes["price"]) * Convert.ToInt32(li.Attributes["quota"]));
}
}
【问题讨论】:
-
您可能希望使用this approach 使您的ListItem 的属性能够在ViewState 中序列化。无论如何,这是该问题的副本。
标签: c# asp.net custom-attributes