DataListd难题.高手进一下.

fanglibang 2005-12-03 01:26:15
怎么判断DataList控件中的DataListItem是为Item项还是为AlternatingItem项..

代码如下:帮我改改...
private void DataListLiuYan_DeleteCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
{
//删除选择的留言

//idCount表留言板的所有id号
ArrayList idCount =new ArrayList();


foreach(DataListItem a in DataListLiuYan.Items)
{
CheckBox check1=(CheckBox)a.FindControl("CheckBox1");//为Items项中的内容

if(check1.Checked==true)
{

int id=int.Parse(((Label)a.FindControl("id1")).Text);
idCount.Add(id);
}

else
{
CheckBox check2=(CheckBox)a.FindControl("CheckBox2");//AlternatingItem中的内容
if(check2.Checked==true)
{

int id=int.Parse(((Label)a.FindControl("id2")).Text);
idCount.Add(id);
}
}


}

if(idCount.Count==0)
{
WebClass.DALParam.UserCodeBackg DelLiuyan=new WebClass.DALParam.UserCodeBackg();
DelLiuyan.DeleteCheckBox(idCount,selectLiuyan.SelectedValue);
DataList();
}


}
...全文
138 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
renyu732 2005-12-03
  • 打赏
  • 举报
回复
根据需要去做.
一般情况下,你操作的是Item里的内容,那就先判断ListItemType.
bidisty 2005-12-03
  • 打赏
  • 举报
回复
if (a.Item.ItemType == ListItemType.Item)
{}
if (a.Item.ItemType == ListItemType.AlternatingItem)
{}

Debug_mq 2005-12-03
  • 打赏
  • 举报
回复
ArrayList idCount =new ArrayList();
定义成全局的,
先判断if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem )

foreach(DataListItem a in DataListLiuYan.Items)
fanglibang 2005-12-03
  • 打赏
  • 举报
回复
关键在这里..
foreach(DataListItem a in DataListLiuYan.Items)
这里我取出一行..我再判断a是否为item项还是其它项

怎么做到.
enjoy330 2005-12-03
  • 打赏
  • 举报
回复
可以的。
fanglibang 2005-12-03
  • 打赏
  • 举报
回复
不行吗?我试了.
fanglibang 2005-12-03
  • 打赏
  • 举报
回复
按钮放在footer中的..
jxufewbt 2005-12-03
  • 打赏
  • 举报
回复
楼上正解
fanglibang 2005-12-03
  • 打赏
  • 举报
回复
我是先把items中的一行取出来再判断是否为item项或AlternatingItem项
这样行吗?
happyfamily 2005-12-03
  • 打赏
  • 举报
回复
就是这一句
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem )
happyfamily 2005-12-03
  • 打赏
  • 举报
回复
private void DataListLiuYan_DeleteCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
{
//删除选择的留言
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem )
{
//idCount表留言板的所有id号
ArrayList idCount =new ArrayList();


foreach(DataListItem a in DataListLiuYan.Items)
{
CheckBox check1=(CheckBox)a.FindControl("CheckBox1");//为Items项中的内容

if(check1.Checked==true)
{

int id=int.Parse(((Label)a.FindControl("id1")).Text);
idCount.Add(id);
}

else
{
CheckBox check2=(CheckBox)a.FindControl("CheckBox2");//AlternatingItem中的内容
if(check2.Checked==true)
{

int id=int.Parse(((Label)a.FindControl("id2")).Text);
idCount.Add(id);
}
}


}

if(idCount.Count==0)
{
WebClass.DALParam.UserCodeBackg DelLiuyan=new WebClass.DALParam.UserCodeBackg();
DelLiuyan.DeleteCheckBox(idCount,selectLiuyan.SelectedValue);
DataList();
}
}


}

62,074

社区成员

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

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

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

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