用户操作
[留言]  [发消息]  [加为好友] 
订阅我的博客
XML聚合    FeedSky
订阅到鲜果
订阅到Google
订阅到抓虾
kingwkb的公告
<script type="text/javascript"><!-- google_ad_client = "pub-3514312439935061"; google_alternate_color = "FFFFFF"; google_ad_width = 160; google_ad_height = 600; google_ad_format = "160x600_as"; google_ad_type = "text_image"; google_ad_channel =""; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> <p> <script type="text/javascript"><!-- google_ad_client = "pub-3514312439935061"; google_ad_width = 120; google_ad_height = 240; google_ad_format = "120x240_as_rimg"; google_cpa_choice = "CAAQw8P8zwEaCCkfm-KkreZAKKG_93M"; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
文章分类
友情连接
asp存储过程
clingingboy blog,asp.net控件开发
DDotNet(RSS)
sodme
在线代理
小说阅读网
数字图像处理
数字图像处理编程入门
存档

转载  得GridView的EmptyDataTemplate中的控件 收藏

这个问题的提出,是我想在Gridview中整理添加记录的功能。
如果有数据的时候,我们可以把空的newTextBox放在FooterTemplate中,在程序里可以用
Gridview1.FooterRow.FindControl("newTextBox")来取得这个控件,完成添加记录的功能。
但如果数据表中没有记录,header和footer都不会显示出来。 这时,只会显示EmptyDataTemplate里的内容。
奇怪的是EmptyDataRow并不是Gridview的成员,于是上面的方法不行了。
找了很久,找到这样一个变通的办法来获得EmptyDataTemplate里的控件:
Dim txbNew As TextBox = GridView1.Controls(0).Controls(0).FindControl("newTextBox")

很变态,但确实可行。

1    Protected Sub btnAddNew_Click(ByVal sender As ObjectByVal e As System.EventArgs)
2        Label1.Text = TypeName(GridView1.Controls(0)).ToString + " "
3        Dim EmptyChildTable As Table = GridView1.Controls(0)
4        Dim EmptyGridView As GridViewRow = EmptyChildTable.Rows(0)
5        Label1.Text = Label1.Text + EmptyGridView.RowType.ToString + " "
6        Dim txbNewCltName As TextBox = EmptyGridView.FindControl("txbNewCltName")
7        Label1.Text = Label1.Text + txbNewCltName.Text
8    End Sub
其中的txbNewCltName和btnAddNew都是放在EmptyTemplate里的控件。
显示的结果是:
ChildTable EmptyDataRow 新添加的内容
可以知道,第一层Control是Table,第二层Control是Row.

发表于 @ 2006年05月22日 13:34:00 | 评论( loading... ) | 编辑| 举报| 收藏

旧一篇:GridView文章,很好的! | 新一篇:Visual studio 2005中Source View中不能切换到Design View的解决方法

  • 发表评论
  • 评论内容:
  •  
Copyright © kingwkb
Powered by CSDN Blog