日期:2014-05-19  浏览次数:20724 次

弱弱的一问
在DataList中的嵌套了DataGrid

在DataGrid中的模板列内有一普通按钮,问如何关联此按钮事件



------解决方案--------------------
bt.Click += new System.EventHandler(Bt_Click);
bt是按钮的名称,Bt_Click是函数的处理函数,
声明为private void Bt_Click(object sender, System.EventArgs e)
------解决方案--------------------
1.手动注册事件
2.可以考虑用__doPostBack()
------解决方案--------------------


private void DataList1_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
string strID = this.DataList1.DataKeys[e.Item.ItemIndex].ToString();
DataSet ds = (DataSet)ViewState[ "Stat "];
DataList dl = e.Item.FindControl( "DataList2 ") as DataList;
dl.ItemDataBound += new DataListItemEventHandler(dl_ItemDataBound);
ds.Tables[0].DefaultView.RowFilter= "[ea_emq_id]= ' " + strID + " ' ";
dl.DataSource = ds.Tables[0];
dl.DataKeyField = "bm_id ";
dl.DataBind();
}
}

private void dl_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DataList dl1 = (DataList)sender;
string strID = dl1.DataKeys[e.Item.ItemIndex].ToString();
DataSet ds = (DataSet)ViewState[ "Material "];
DataList dl = e.Item.FindControl( "DataList3 ") as DataList;
DataRow[] drs = ds.Tables[0].Select( "[bm_id]= ' " + strID + " ' ");
dl.DataSource = drs;
dl.DataBind();
}
}
------解决方案--------------------
*