Repeater中嵌套CheckBox

:前台
<TABLE cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr>
<td align="right" width="70%"><INPUT type="button" value="创建产品分组" onclick="PostCreate()">&nbsp;</td>
<td align="center" width="20%">&nbsp;<INPUT id="post" onclick="Post()" type="button" value="发布新产品" name="post"></td>
<td align="center"><asp:button id="btnDelete" Text="删除" runat="server"></asp:button><asp:textbox id="tbxDelValid" style="DISPLAY: none" runat="server" EnableViewState="False"></asp:textbox>&nbsp;&nbsp;
<asp:textbox id="tbxDelId" style="DISPLAY: none" runat="server" EnableViewState="False"></asp:textbox><asp:textbox id="tbxDelImg" style="DISPLAY: none" runat="server" EnableViewState="False"></asp:textbox><asp:textbox id="tbxDelCId" style="DISPLAY: none" runat="server" EnableViewState="False"></asp:textbox></td>
</tr>
</TABLE>
<asp:repeater id="GroupRepeater" runat="server" EnableViewState="False">
<ItemTemplate>
<%# (intCount++ == 0) ? "" : ""%>
<%# (intCheck == 0) ? "" : ""%>
<tr bgcolor="#ffffff">
<td bgcolor="#e0ffff" width="80%">
<table cellSpacing="1" cellPadding="1" width="100%" border="0">
<tr>
<td width="80%"><img src="/images/OpenBox.gif" id="img<%# intCount%>" onclick="javascript:showhide(offer<%# intCount%>,img<%# intCount%>);" onMouseOver="this.style.cursor='hand'">&nbsp;&nbsp;<a href="javascript:showhide(offer<%# intCount%>,document.all['img<%# intCount%>']);"><%# DataBinder.Eval(Container.DataItem,"GroupName")%></a></td>
<td>
<%# (DataBinder.Eval(Container.DataItem,"GroupName") == "未分类") ? "&nbsp;" : "<a href='GroupCreate.aspx?id=" + DataBinder.Eval(Container.DataItem,"id") + "'>修改</a>"%>
</td>
<td>
<asp:LinkButton id="lbtnDel" runat="server" CommandName="delete" CommandArgument='<% #DataBinder.Eval(Container.DataItem,"id")%>' Visible='<%# (DataBinder.Eval(Container.DataItem,"GroupName") == "未分类") ? bool.Parse("False") : bool.Parse("True")%>'>删除</asp:LinkButton></td>
</tr>
</table>
</td>
</tr>
<tbody id="offer<%# intCount %>">
<tr bgcolor="#ffffff">
<td>
<asp:Repeater id="ChildRepeater" runat="server">
<ItemTemplate>
<tr bgcolor="#ffffff">
<td align="center"><%# DataBinder.Eval(Container.DataItem,"Valid")%></td>
<td align="center">
<asp:Image id="proImg" runat="server" ImageUrl='<%# GetImgUrl(DataBinder.Eval(Container.DataItem,"SmallPictrue", null))%>'>
</asp:Image></td>
<td><a href="/Products/View/<%# DataBinder.Eval(Container.DataItem,"Id")%>.htm" target="_blank"><%# Convert.ToString(DataBinder.Eval(Container.DataItem,"ProductName")).Length > 10 ? Convert.ToString(DataBinder.Eval(Container.DataItem,"ProductName")).Substring(0,10) + "..." : DataBinder.Eval(Container.DataItem,"ProductName")%></a></td>
<td><a href="/Products/View/<%# DataBinder.Eval(Container.DataItem,"Id")%>.htm" target="_blank"><%# Convert.ToString(DataBinder.Eval(Container.DataItem,"Details")).Length > 19 ? Convert.ToString(DataBinder.Eval(Container.DataItem,"Details")).Substring(0,19) + "..." : DataBinder.Eval(Container.DataItem,"Details")%></a></td>
<td align="center"><a href='Modify.aspx?id=<%# DataBinder.Eval(Container.DataItem,"id")%>'>编辑</a></td>
<td align="center"><input type="checkbox" id="select<%# intCount%>" name="select<%# intCount%>" value='<%# DataBinder.Eval(Container.DataItem,"id")%>|<%# DataBinder.Eval(Container.DataItem,"SmallPictrue")%>,<%# DataBinder.Eval(Container.DataItem,"BigPictrue")%>|<%# DataBinder.Eval(Container.DataItem,"CategoryId")%>|<%# DataBinder.Eval(Container.DataItem,"ValidValue")%>' onclick="Javascript:SelectChange(this, checkall<%# intCount%>)"></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
<HeaderTemplate>
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#cccccc">
<tr bgcolor="#f0f0f0">
<td align="center" width="80">审核标志</td>
<td align="center" width="100">产品图片</td>
<td align="center" width="200">产品名称</td>
<td align="center" width="200">描述</td>
<td align="center" width="50">编辑</td>
<td align="center" width="20"><input type="checkbox" name="checkall<%# intCount%>" id="checkall<%# intCount%>" value="|||" onclick="Javascript:CheckAll(this, '<%# intCount%>')"></td>
</tr>
</HeaderTemplate>
</asp:Repeater>
</td>
</tr>
</tbody>
</ItemTemplate>
<HeaderTemplate>
<TABLE cellSpacing="1" cellPadding="1" width="98%" border="0" bgcolor="#c0c0c0" align="center">
</HeaderTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:repeater>

lovewindy(LOVE风云) 于 2005-8-18 10:56:50

前台的JS代码,就接在上面发的代码下面,因为太长了,不让发
<script language="javascript">
<!--
function showhide(t_id,i_id){//显示隐藏程序
var t_id;//表格ID
var i_id;//图片ID
var on_img="/Images/OpenBox.gif";//打开时图片
var off_img="/Images/CloseBox.gif";//隐藏时图片
if (t_id.style.display == "none") {//如果为隐藏状态
t_id.style.display="";//切换为显示状态
i_id.src=on_img;//换图
}
else{//否则
t_id.style.display="none";//切换为隐藏状态
i_id.src=off_img;
}//换图

}

-->

</script>
<SCRIPT language="javascript">
<!--
function CheckAll(thisbox, num)
{
var ids = document.getElementsByName("select" + num);
var strId = "";
var strImg = "";
var strCId = "";
var strValue = "";
var strValid = "";
var valueArr = new Array();
if (ids != null)
{
for(i = 0; i < ids.length; i++)
{
var obj = ids(i);
obj.checked = thisbox.checked;
strValue = ids(i).value;

valueArr = strValue.split('|');
strId += valueArr[0] + ",";
strImg += valueArr[1] + ",";
strCId += valueArr[2] + ",";
strValid += valueArr[3] + ",";
}
if (!thisbox.checked)
{
thisbox.value = "|||";
return;
}
if (strId.length > 0)
{
thisbox.value = strId + '|' + strImg + '|' + strCId + '|' + strValid;
}
}
}

function SelectChange(thisbox, parentbox)
{
var valueArr = new Array();
valueArr = parentbox.value.split('|');
//alert(valueArr);

var strId = valueArr[0];
var strImg = valueArr[1];
var strCId = valueArr[2];
var strValid = valueArr[3];


valueArr = thisbox.value.split('|');
var strChildId = valueArr[0];
var strChildImg = valueArr[1];
var strChildCId = valueArr[2];
var strChildValid = valueArr[3];
//alert(valueArr);

if (thisbox.checked)
{
strId += strChildId + ",";
strImg += strChildImg + ",";
strCId += strChildCId + ",";
strValid += strChildValid + ",";
parentbox.value = strId + '|' + strImg + '|' + strCId + '|' + strValid;
return;
}
else
{
var strNewId = strId.replace((strChildId + ","), "");
var strNewImg = strImg.replace((strChildImg + ","), "");
var strNewCId = strCId.replace((strChildCId + ","), "");
var strNewValid = strValid.replace((strChildValid + ","), "");
parentbox.value = strNewId + '|' + strNewImg + '|' + strNewCId + '|' + strNewValid;
}
}
-->
</SCRIPT>
<script language="javascript">
<!--
function PostCreate()
{
location.href="GroupCreate.aspx?menu=Products";
}
function Post()
{
location.href="post.aspx?menu=Products";
}

function GetCheckNum()
{
var valueArr = new Array();
var strId ="";
var strImg = "";
var strCId = "";
var strValid = "";

var count = document.forms[0].elements.length;

for (var i=0;i<count;i++)
{
var e = document.forms[0].elements[i];

if (e.name.indexOf("select") && e.type == "checkbox")//原本应该e.name.indexOf("checkall"),但执行却出错
{

valueArr = e.value.split('|');
if (valueArr[0] != '')
{
strId += valueArr[0];
strImg += valueArr[1];
strCId += valueArr[2];
strValid += valueArr[3];
}
}
}

if(strId.length > 0)
{
strId = strId.substring(0, strId.length - 1);
strImg = strImg.substring(0, strImg.length - 1);
strCId = strCId.substring(0, strCId.length - 1);
strValid = strValid.substring(0, strValid.length - 1);

var theIdBox = document.getElementById("MemberProductsList_tbxDelId");//由于是自定义控件内的服务器控件,自动生成时,会在名字后加上标识,所以该控件名应该为MemberProductsList_tbxDelId
var theImgBox = document.getElementById("MemberProductsList_tbxDelImg");
var theCIdBox = document.getElementById("MemberProductsList_tbxDelCId");
var theValidBox = document.getElementById("MemberProductsList_tbxDelValid");

theIdBox.value = strId;
theImgBox.value = strImg;
theCIdBox.value = strCId;
theValidBox.value = strValid;
return confirm('确定删除!');
}
else
{
alert('请选择想删除的产品!');
return false;
}
}
-->
</script>
<script language="javascript">
<!--
function CheckGroupDel(num)
{
var theSubItem = document.getElementById("select" + num);
if (theSubItem == null)
{
return confirm('确定删除!');
}
else
{
alert('被删分组下不能有产品!');
return false;
}
}
-->
</script>
lovewindy(LOVE风云) 于 2005-8-18 10:58:38

后台一个删除事件
private void btnDelete_Click(object sender, EventArgs e)
{
string strDelId = this.tbxDelId.Text;
string strDelImg = this.tbxDelImg.Text;
string strDelCId = this.tbxDelCId.Text;
string strDelValid = this.tbxDelValid.Text;

//Product objProduct = new Product();
Product objProduct = new Product();
if(objProduct.Delete(strDelId, strDelCId, strDelValid))
{
this.DelImage(strDelImg);
this.DataBind();
}

}
posted @ 2006-10-12 19:09  '.Elvis.'  阅读(791)  评论(0编辑  收藏  举报