【发布时间】:2011-03-09 01:39:53
【问题描述】:
如何在 gridview 中动态添加页脚行。带有文本框..请给出任何想法...
【问题讨论】:
-
“页脚行”是指要填充网格中的最后一行,还是要与所有其他行分开并锚定到底部的行网格视图?
标签: c# asp.net gridview footer
如何在 gridview 中动态添加页脚行。带有文本框..请给出任何想法...
【问题讨论】:
标签: c# asp.net gridview footer
由于 IMO 网格视图中只能有一个页脚行,因此最好通过将网格视图的 ShowFooter 属性设置为 true 来添加页脚行。设置
FooterStyle 属性在这里会有所帮助。
进入编程部分,
protected void MyGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Footer)
{
TextBox txt = new TextBox();
// set properties of text box
e.Row.Cells[0].Controls.Add(txt);
}
}
试试这个并发表评论。
编辑:这会有所帮助 http://www.asp.net/data-access/tutorials/displaying-summary-information-in-the-gridview-s-footer-cs
【讨论】:
只有一个页脚行,所以你可以控制它是否在代码中动态显示,如下所示:
if (GridView.EditIndex == -1)
GridViewProject.FooterRow.Visible = true;
}
else
{
GridViewProject.FooterRow.Visible = false;
}
在 RowDataBound 事件中检查行类型并设置所需的任何默认值: 我发现尽可能使用下拉列表来防止用户输入错误数据很有用
switch (e.Row.RowType)
{
case DataControlRowType.Header:
case DataControlRowType.DataRow:
case DataControlRowType.Footer:
//popluate ddls
}
【讨论】:
请按照步骤操作
1.将DataSource分配给Gridview
2.在RowDataBound中找到GridView的RowType
3. 如果 RowType 是 FooterRow
4.在行中动态添加文本框或所需控件(每一行都呈现为TableRow)
你可以自定义它。
【讨论】: