GridView数据源为空时,找不到FooterRow

本文探讨了在ASP.NET中使用GridView控件时遇到的问题,特别是当试图在没有数据的情况下显示Footer Row,并对其进行操作时遇到的挑战。文章讨论了如何自定义空数据状态下的GridView表现,并提出了对于Footer Row在不同情况下表现不一致的解决思路。

在GridView的Command事件中可以用下面的语句来找到:

GridViewRow gridViewRow = ((Control)e.CommandSource).BindingContainer as GridViewRow;

 

GridView中控件的事件中,可以用下面的语句来找到:
GridViewRow gridViewRow = (sender as TextBox).Parent.Parent as GridViewRow;
string itemNo = ((TextBox)(gridViewRow.FindControl("TextBoxPartNoNew"))).Text.Trim();

在Page_Load怎么找到,还没有想到?

下面资料转自:http://www.itzhe.cn/html/web/ASP.NET/20071127/22928_2.html

用 gridview 实现插入功能时遇到的问题
// create a new header row 
GridViewRow headerRow = base.CreateRow(-1-1, DataControlRowType.Header, DataControlRowState.Normal); 
this.InitializeRow(headerRow, fields); 

// add the header row to the table 
table.Rows.Add(headerRow); 


// create the empty row 
GridViewRow emptyRow = new GridViewRow(-1-1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal); 
TableCell cell 
= new TableCell(); itzhe.cn 
cell.ColumnSpan 
= fields.Length; 
cell.Width 
= Unit.Percentage(100); 

// respect the precedence order if both EmptyDataTemplate 
// and EmptyDataText are both supplied  
if (this.EmptyDataTemplate != null

this.EmptyDataTemplate.InstantiateIn(cell); 

else if (!string.IsNullOrEmpty(this.EmptyDataText)) 

cell.Controls.Add(
new LiteralControl(EmptyDataText)); 
IT 者



emptyRow.Cells.Add(cell); 
table.Rows.Add(emptyRow); 

//if (this.ShowFooterWhenEmpty) 
//
// create footer row 
GridViewRow footerRow = base.CreateRow(-1-1, DataControlRowType.Footer, DataControlRowState.Normal); 
this.InitializeRow(footerRow, fields); 

// add the footer to the table 
table.Rows.Add(footerRow); 
//

this.Controls.Clear(); 
www.itzhe.cn

this.Controls.Add(table); 
this.ShowFooter = true

return rows; 




功能实现了,没有数据的时候header和footer都能显示,我把插入数据要输入的项目都放在footer里面,所以没有数据的时候,始终会显示一条插入纪录,但当我提交以后,gridView.FooterRow.FindControl( "tb_foot_name ") 返回空值。但假如表格里边本身有数据的话 gridView.FooterRow.FindControl( "tb_foot_name ")能够返回对象,区别是:
但没有数据时,footer是我自己创建的,有数据时footer是系统创建的。
请问大家,有何良策

谢谢
本篇文章来源于 www.itzhe.cn 原文链接:http://www.itzhe.cn/html/web/ASP.NET/20071127/22928_2.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值