首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

2005里用gridview怎么实现收缩、展开(带+ -号的那种)效果

2011-12-20 
2005里用gridview如何实现收缩、展开(带+ -号的那种)效果?如题,之前看过孟子兄的文章,但我需要的是更复杂的

2005里用gridview如何实现收缩、展开(带+ -号的那种)效果?
如题,之前看过孟子兄的文章,但我需要的是更复杂的效果,请给点例子,谢谢!

点击   +   号展开,点击   -   号收缩。

[解决办法]
//控件主行显示按钮、子行不显示
protected void RecoveriesGridView_RowCreated(object sender, GridViewRowEventArgs e) {
if (e.Row.RowType == DataControlRowType.DataRow) {
object PaymentSubCategoryId = recoveriesGridView.DataKeys[e.Row.DataItemIndex][ "PaymentSubCategoryId "];
if (!string.IsNullOrEmpty(WebConvert.ToString(PaymentSubCategoryId) )) {
((ImageButton)e.Row.FindControl( "hiddenImageButton ")).Visible = false;
Literal literal = new Literal();
literal.Text = WebConvert.ToString( "      ");
e.Row.Cells[0].Controls.AddAt(0, literal);
} else {
((ImageButton)e.Row.FindControl( "hiddenImageButton ")).CommandArgument = WebConvert.ToString(e.Row.DataItemIndex);
}
}
}

//收缩、展开按钮事件

protected void RecoveriesGridView_RowCommand(object sender, CommandEventArgs e) {
if (e.CommandName == "HiddenRows ") {
int rowId = WebConvert.ToInt32(e.CommandArgument);
object currentPaymentCategoryId=recoveriesGridView.DataKeys[rowId][ "PaymentCategoryId "];
for (int i = rowId + 1; i < recoveriesGridView.Rows.Count; i++) {
if (recoveriesGridView.DataKeys[i][ "PaymentCategoryId "].Equals(currentPaymentCategoryId)) {
recoveriesGridView.Rows[i].Visible = recoveriesGridView.Rows[i].Visible == false ? true : false;
}
}
((ImageButton)recoveriesGridView.Rows[rowId].FindControl( "hiddenImageButton ")).ImageUrl = ((ImageButton)recoveriesGridView.Rows[rowId].FindControl( "hiddenImageButton ")).ImageUrl == "~/Image/Collapse.jpg " ? "~/Image/Expand.jpg " : "~/Image/Collapse.jpg ";
}
}

热点排行