Reference to gridview control

Discussion in 'ASP .Net Datagrid Control' started by Lucas Hernandez, Oct 25, 2006.

  1. Anybody here knows how to make reference to en emptydatatemplate control?
    Lucas Hernandez, Oct 25, 2006
    #1
    1. Advertising

  2. Hi Lucas,

    I'm not quite sure what you need to know, but you can check the row type
    each time a row is created and if it's the empty row, get a reference to the
    content of the template.

    Here's a little example. Let us know if this helps?

    Ken
    Microsoft MVP [ASP.NET]


    <%@ Page Language="VB" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">

    Protected Sub Page_Load _
    (ByVal sender As Object, _
    ByVal e As System.EventArgs)
    If Not IsPostBack Then
    GridView1.DataSource = CreateEmptyDataSource()
    GridView1.DataBind()
    End If

    End Sub

    Function CreateEmptyDataSource() As Data.DataTable
    Dim dt As New Data.DataTable
    dt.Columns.Add(New Data.DataColumn _
    ("IntegerValue", GetType(Int32)))
    dt.Columns.Add(New Data.DataColumn _
    ("StringValue", GetType(String)))
    dt.Columns.Add(New Data.DataColumn _
    ("CurrencyValue", GetType(Double)))
    dt.Columns.Add(New Data.DataColumn _
    ("Boolean", GetType(Boolean)))
    dt.Clear()
    Return dt
    End Function

    Protected Sub GridView1_RowCreated _
    (ByVal sender As Object, _
    ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
    If e.Row.RowType = DataControlRowType.EmptyDataRow Then
    Dim lbl As Label
    lbl = e.Row.FindControl("lblEmpty")
    lbl.Text = "Okay this is the empty text"
    End If
    End Sub
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Get a reference to an empty data message</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:gridview id="GridView1" runat="server"
    onrowcreated="GridView1_RowCreated">
    <emptydatatemplate>
    <asp:label runat="server" id="lblEmpty"
    text="Empty, eh?"></asp:label>
    </emptydatatemplate>
    </asp:gridview>
    </div>
    </form>
    </body>
    </html>

    "Lucas Hernandez" <> wrote in message
    news:33fed$453f820e$d0669864$...
    > Anybody here knows how to make reference to en emptydatatemplate control?
    Ken Cox [Microsoft MVP], Oct 26, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ashish_gokhale
    Replies:
    0
    Views:
    424
    ashish_gokhale
    May 5, 2005
  2. Chris Kettenbach
    Replies:
    2
    Views:
    502
    Chris Kettenbach
    Jun 28, 2005
  3. =?Utf-8?B?bWdvbnphbGVzMw==?=

    GridView Hierarchical View - Gridview in Gridview

    =?Utf-8?B?bWdvbnphbGVzMw==?=, May 9, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    17,945
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    May 9, 2006
  4. Get reference to control in gridview at runtime...

    , Jul 3, 2007, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    915
  5. John Walker

    Reference "Programmatic" Gridview Control on Postback

    John Walker, Jun 9, 2008, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    184
    Peter Bucher [MVP]
    Jun 12, 2008
Loading...

Share This Page