repeater
循环一个选项卡div
每个div内都有个CheckBoxList <asp:Repeater ID="rptrLanguageDivs" runat="server" OnItemDataBound="rptrLanguageDivs_ItemDataBound">
<ItemTemplate>
<div id="idTab_Info<%# Container.ItemIndex+2 %>" class="tab">
<i>
<%=GetLocaleResourceString("Admin.Localizable.EmptyFieldNote")%></i>
<asp:Label ID="lblLanguageId" runat="server" Text='<%#Eval("LanguageId") %>' Visible="false"></asp:Label>
<table class="adminContent">
<tr>
<td class="adminTitle">
<nopCommerce:ToolTipLabel runat="server" ID="lblLocalizedAttributeName" Text="<% $NopResources:Admin.ProductVariantAttributeValues.New.Name %>"
ToolTip="<% $NopResources:Admin.ProductVariantAttributeValues.New.Name.Tooltip %>"
ToolTipImage="~/Administration/Common/ico-help.gif" />
</td>
<td class="adminData">
<%-- <asp:TextBox runat="server" CssClass="adminInput" ID="txtNewLocalizedName" />--%>
<asp:CheckBoxList ID="cbl_ProductAttributeValueList" runat="server" RepeatDirection="horizontal" >
</asp:CheckBoxList>
</td>
</tr>
</table>
</div>
</ItemTemplate>
</asp:Repeater>绑定 protected void rptrLanguageDivs_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
ProductVariantAttribute pva = ProductAttributeService.GetProductVariantAttributeById(this.ProductVariantAttributeId);
int ProductAttributeId = 0;
if (pva != null)
{
ProductAttributeId=pva.ProductAttributeId;
}
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
Language lg = (Language)e.Item.DataItem;
int LanguageID = lg.LanguageId;
CheckBoxList ckb = (CheckBoxList)e.Item.FindControl("cbl_ProductAttributeValueList");
ckb.DataSource = ProductAttributeService.GetProductAttributeValues(LanguageID, ProductAttributeId, null);
ckb.DataTextField = "Name";
ckb.DataValueField = "ProductAttributeValueID";
ckb.DataBind();
}
}
在外部有个按钮
点击如何判断 必须有一个CheckBoxList内被打勾,并且只能存在一个CheckBoxList被打勾
并取值
循环一个选项卡div
每个div内都有个CheckBoxList <asp:Repeater ID="rptrLanguageDivs" runat="server" OnItemDataBound="rptrLanguageDivs_ItemDataBound">
<ItemTemplate>
<div id="idTab_Info<%# Container.ItemIndex+2 %>" class="tab">
<i>
<%=GetLocaleResourceString("Admin.Localizable.EmptyFieldNote")%></i>
<asp:Label ID="lblLanguageId" runat="server" Text='<%#Eval("LanguageId") %>' Visible="false"></asp:Label>
<table class="adminContent">
<tr>
<td class="adminTitle">
<nopCommerce:ToolTipLabel runat="server" ID="lblLocalizedAttributeName" Text="<% $NopResources:Admin.ProductVariantAttributeValues.New.Name %>"
ToolTip="<% $NopResources:Admin.ProductVariantAttributeValues.New.Name.Tooltip %>"
ToolTipImage="~/Administration/Common/ico-help.gif" />
</td>
<td class="adminData">
<%-- <asp:TextBox runat="server" CssClass="adminInput" ID="txtNewLocalizedName" />--%>
<asp:CheckBoxList ID="cbl_ProductAttributeValueList" runat="server" RepeatDirection="horizontal" >
</asp:CheckBoxList>
</td>
</tr>
</table>
</div>
</ItemTemplate>
</asp:Repeater>绑定 protected void rptrLanguageDivs_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
ProductVariantAttribute pva = ProductAttributeService.GetProductVariantAttributeById(this.ProductVariantAttributeId);
int ProductAttributeId = 0;
if (pva != null)
{
ProductAttributeId=pva.ProductAttributeId;
}
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
Language lg = (Language)e.Item.DataItem;
int LanguageID = lg.LanguageId;
CheckBoxList ckb = (CheckBoxList)e.Item.FindControl("cbl_ProductAttributeValueList");
ckb.DataSource = ProductAttributeService.GetProductAttributeValues(LanguageID, ProductAttributeId, null);
ckb.DataTextField = "Name";
ckb.DataValueField = "ProductAttributeValueID";
ckb.DataBind();
}
}
在外部有个按钮
点击如何判断 必须有一个CheckBoxList内被打勾,并且只能存在一个CheckBoxList被打勾
并取值
然后再提交呢?
分不是问题 问题是怎么解决这个问题
就是选项卡的
<div id="idTab_Info<%# Container.ItemIndex+2 %>" class="tab">
ID都是固定的 循环判断固定id下的checklistbox
{
CheckBox cb = (CheckBox)item.FindControl("cb_id");
if (cb.Checked)
}
{
bool = false;
for (int i = 0; i < rptrLanguageDivs.Items.Count; i++)
{
CheckBoxList ckb = (CheckBoxList)rptrLanguageDivs.Items[i].FindControl("cbl_ProductAttributeValueList");
if (-1 != ckb.SelectedIndex)
{
= true;
}
}
if ()
{
Response.Write("有选中");
}
else
{
Response.Write("无选中");
}
}
<i>
请注意,如果一个字段为空,标准字段将被使用.</i>
<table class="adminContent">
<tbody><tr>
<td class="adminTitle">
<span class="nop-tooltip">
<img id="ctl00_cph1_ctrlProductVariantAttributeValues_rptrLanguageDivs_ctl00_lblLocalizedAttributeName_imgToolTip" title="属性值的名称,例如'蓝'的颜色属性" src="Common/ico-help.gif" alt="?" style="border-width:0px;">
<span id="ctl00_cph1_ctrlProductVariantAttributeValues_rptrLanguageDivs_ctl00_lblLocalizedAttributeName_lblValue" title="属性值的名称,例如'蓝'的颜色属性">名称</span>
</span>
</td>
<td class="adminData">
<table id="ctl00_cph1_ctrlProductVariantAttributeValues_rptrLanguageDivs_ctl00_cbl_ProductAttributeValueList" border="0">
<tbody><tr>
<td><input id="ctl00_cph1_ctrlProductVariantAttributeValues_rptrLanguageDivs_ctl00_cbl_ProductAttributeValueList_0" type="checkbox" name="ctl00$cph1$ctrlProductVariantAttributeValues$rptrLanguageDivs$ctl00$cbl_ProductAttributeValueList$0"><label for="ctl00_cph1_ctrlProductVariantAttributeValues_rptrLanguageDivs_ctl00_cbl_ProductAttributeValueList_0">赤</label></td>
</tr>
</tbody></table>
</td>
</tr>
</tbody></table>
</div>
已上图
Js代码:
function CheckList(obj) {
obj.checked === true && $(".chkselect").not($(obj)).each(function () { $(this).get(0).checked = false; })
}
Html代码:
<div id="idTab_Info2" class="tab" style="display: block;">
<i>请注意,如果一个字段为空,标准字段将被使用.</i>
<table class="adminContent">
<tbody>
<tr>
<td class="adminTitle">
<span class="nop-tooltip">
<img id="ctl00_cph1_ctrlProductVariantAttributeValues_rptrLanguageDivs_ctl00_lblLocalizedAttributeName_imgToolTip"
title="属性值的名称,例如'蓝'的颜色属性" src="Common/ico-help.gif" alt="?" style="border-width: 0px;">
<span id="ctl00_cph1_ctrlProductVariantAttributeValues_rptrLanguageDivs_ctl00_lblLocalizedAttributeName_lblValue"
title="属性值的名称,例如'蓝'的颜色属性">名称</span> </span>
</td>
<td class="adminData">
<table id="ctl00_cph1_ctrlProductVariantAttributeValues_rptrLanguageDivs_ctl00_cbl_ProductAttributeValueList"
border="0">
<tbody>
<tr>
<td>
<input id="ctl00_cph1_ctrlProductVariantAttributeValues_rptrLanguageDivs_ctl00_cbl_ProductAttributeValueList_0"
type="checkbox" name="ctl00$cph1$ctrlProductVariantAttributeValues$rptrLanguageDivs$ctl00$cbl_ProductAttributeValueList$0"
class="chkselect" onclick="CheckList(this)"><label for="ctl00_cph1_ctrlProductVariantAttributeValues_rptrLanguageDivs_ctl00_cbl_ProductAttributeValueList_0">赤</label>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
加了一个class= "chkselect" 加了一个onclick = "CheckList(this)"
他说的是浏览器自动生成的这两句代码吧~~~
http://bbs.csdn.net/topics/390508898