zoukankan      html  css  js  c++  java
  • 获得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()Sub btnAddNew_Click(ByVal sender As Object, ByVal 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.

    http://ebakeshop.spaces.live.com/Blog/cns!1A66D6C80502E805!316.entry

  • 相关阅读:
    HttpServletRequest字符集问题
    原码反码补码
    无符号1byte转int
    初识spark的MLP模型
    冗余系统必要性
    shiro的rememberMe不生效
    阅读笔记-异常
    优雅的处理异常
    使用Maven搭建SpringMVC
    Jmeter发送soap请求
  • 原文地址:https://www.cnblogs.com/shiningrise/p/1613528.html
Copyright © 2011-2022 走看看