DataList1中的嵌套一个DataList2.通过DataList1的ItemDataBound事件中查找DataList2控件,给DataList2设置数据源,绑定数据.
在DataList2中的ItemDataBound事件中手动的绑定.现在有个问题是,我在DataList2中有个按钮.CommandName="Add",
private void DataList2_ItemCommand(object source, DataListCommandEventArgs e) 就是不能执行,为什么?
private void DataList1_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem)
{
DataRow dr=ds.Tables["Types"].Rows[e.Item.ItemIndex];
DataList DataList2 = (DataList)e.Item.FindControl("DataList2");
SqlParameter[] paras = new SqlParameter[]{
new SqlParameter("@TypeId",SqlDbType.Int)
};
paras[0].Value=dr["RecId"];
ds=conn.ExecuteProc("Products_SelectForTypeId",paras,"Products");
DataList2.DataSource=ds.Tables["Products"].DefaultView; //绑定事件可以正常.
DataList2.ItemDataBound+=new DataListItemEventHandler(DataList2_ItemDataBound);
//DataList2.ItemCommand事件不能执行,为什么?如何解决?
DataList2.ItemCommand+=new DataListCommandEventHandler(DataList2_ItemCommand);
DataList2.DataBind();
ds.Tables.Remove("Products");
}
}
private void DataList2_ItemDataBound(object sender, DataListItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem)
{
DataRow dr=ds.Tables["Products"].Rows[e.Item.ItemIndex];
Literal lbSmallImage=(Literal)e.Item.FindControl("lbSmallImage");
lbSmallImage.Text="<a href='ProductShow.aspx?RecId="+dr["RecId"].ToString()+"'><img src='../images/Products/"
+dr["BigImage_Save"].ToString()+"' border=0 height=75 width=75></a><br>"; Literal lbName=(Literal)e.Item.FindControl("lbName");
lbName.Text=dr["Name"].ToString(); Literal lbSCPrice=(Literal)e.Item.FindControl("lbSCPrice");
lbSCPrice.Text=dr["SCPrice"].ToString(); Literal lbSDPrice=(Literal)e.Item.FindControl("lbSDPrice");
lbSDPrice.Text=dr["SDPrice"].ToString(); Literal lbCJPrice=(Literal)e.Item.FindControl("lbCJPrice");
lbCJPrice.Text=dr["CJPrice"].ToString(); HyperLink hlXQ=(HyperLink)e.Item.FindControl("hlXQ");
hlXQ.NavigateUrl="ProductShow.aspx?RecId="+dr["RecId"].ToString(); HyperLink hlLB=(HyperLink)e.Item.FindControl("hlLB");
hlLB.NavigateUrl="ProductsListShow.aspx?TypeId="+dr["TypeId"].ToString();
}
}private void DataList2_ItemCommand(object source, DataListCommandEventArgs e)
{
Response.Write("aaaaaaaaaaaaaaaaaaaaa");
}
在DataList2中的ItemDataBound事件中手动的绑定.现在有个问题是,我在DataList2中有个按钮.CommandName="Add",
private void DataList2_ItemCommand(object source, DataListCommandEventArgs e) 就是不能执行,为什么?
private void DataList1_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem)
{
DataRow dr=ds.Tables["Types"].Rows[e.Item.ItemIndex];
DataList DataList2 = (DataList)e.Item.FindControl("DataList2");
SqlParameter[] paras = new SqlParameter[]{
new SqlParameter("@TypeId",SqlDbType.Int)
};
paras[0].Value=dr["RecId"];
ds=conn.ExecuteProc("Products_SelectForTypeId",paras,"Products");
DataList2.DataSource=ds.Tables["Products"].DefaultView; //绑定事件可以正常.
DataList2.ItemDataBound+=new DataListItemEventHandler(DataList2_ItemDataBound);
//DataList2.ItemCommand事件不能执行,为什么?如何解决?
DataList2.ItemCommand+=new DataListCommandEventHandler(DataList2_ItemCommand);
DataList2.DataBind();
ds.Tables.Remove("Products");
}
}
private void DataList2_ItemDataBound(object sender, DataListItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem)
{
DataRow dr=ds.Tables["Products"].Rows[e.Item.ItemIndex];
Literal lbSmallImage=(Literal)e.Item.FindControl("lbSmallImage");
lbSmallImage.Text="<a href='ProductShow.aspx?RecId="+dr["RecId"].ToString()+"'><img src='../images/Products/"
+dr["BigImage_Save"].ToString()+"' border=0 height=75 width=75></a><br>"; Literal lbName=(Literal)e.Item.FindControl("lbName");
lbName.Text=dr["Name"].ToString(); Literal lbSCPrice=(Literal)e.Item.FindControl("lbSCPrice");
lbSCPrice.Text=dr["SCPrice"].ToString(); Literal lbSDPrice=(Literal)e.Item.FindControl("lbSDPrice");
lbSDPrice.Text=dr["SDPrice"].ToString(); Literal lbCJPrice=(Literal)e.Item.FindControl("lbCJPrice");
lbCJPrice.Text=dr["CJPrice"].ToString(); HyperLink hlXQ=(HyperLink)e.Item.FindControl("hlXQ");
hlXQ.NavigateUrl="ProductShow.aspx?RecId="+dr["RecId"].ToString(); HyperLink hlLB=(HyperLink)e.Item.FindControl("hlLB");
hlLB.NavigateUrl="ProductsListShow.aspx?TypeId="+dr["TypeId"].ToString();
}
}private void DataList2_ItemCommand(object source, DataListCommandEventArgs e)
{
Response.Write("aaaaaaaaaaaaaaaaaaaaa");
}
解决方案 »
- 咨询下c#和.net教材
- 提问的时候如何插入图片
- HttpRuntime.Cache.add方法有么
- 急急!!!!!!!!!
- 调查:各位同行使用ajax技术时,是用magicajax,ajaxpro,还是AjaxControlToolkit,或者是最原始的做法,不用工具包,全部自己写??
- 问一下高人关于论坛的问题
- 请各位进来看看,然后写上你的看法、意见和建议==解疑惑
- 请教大侠:winxp sp2 操作系统是不是不能装vs2003啊?如果要装上,我该怎么处理才行啊?
- 高分请教asp.net中,移动web程序里怎么使用javascript?
- “/”应用程序中的服务器错误。
- 做了一论坛,大伙逛一下,注下册最好 : ) 有美女哟。
- 奇的怪了,我在后台代码里用Request.Form["chechkname"]获取不了前端checkbox控件,
AddHandler CType(dgListArticle.Items(i).Cells(5).FindControl("DropDownList1"), DropDownList).SelectedIndexChanged, AddressOf Selectchange
private void DataList2_ItemDataBound(object sender, DataListItemEventArgs e)
{
}
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DataTable dt = da.Clone ();
DataRow[] arrdr = da.Select ("b_class='" + ((Literal)e.Item.FindControl ("title")).Text + "'");
for (int i=0;i<arrdr.Length;i++)
{
dt.ImportRow (arrdr[i]);
} Control c = e.Item.FindControl ("InfoList");
if (c != null)
{
((Repeater)c).DataSource = dt;
((Repeater)c).DataBind ();
}
}
}
请帮忙哦
http://community.csdn.net/Expert/topic/3600/3600123.xml?temp=.9944727里面思归老大的回答 请注意object的使用 也许能给你点启发