accessing control in EmptyDataTemplate

Discussion in 'ASP .Net' started by Jeff, Nov 4, 2008.

  1. Jeff

    Jeff Guest

    hi

    asp.net 2.0

    I have a GridView here with some controls in it's EmptyDataTemplate. I'm
    wondering how I can get access to those controls. I've tryed using
    FindControl, but that doesn't work because EmptyDataTemplate doesn't have
    that method

    <EmptyDataTemplate>
    <asp:TextBox ID="txtCode" runat="server"></asp:TextBox>
    <asp:TextBox ID="txtDesc" runat="server"></asp:TextBox>
    <asp:LinkButton ID="lbEmpty" OnClick="lbEmpty_Click" runat="server">Legg
    til</asp:LinkButton>
    </EmptyDataTemplate>

    (BTW, it is in the lbEmpty_Click method I'm trying to access the txtCode and
    txtDesc textboxes. it's here the problem occur)

    Any suggestions?
     
    Jeff, Nov 4, 2008
    #1
    1. Advertising

  2. Jeff

    bruce barker Guest

    try:


    void lbEmpty_Click(Object sender, EventArgs e)
    {
    var parent = ((Control) sender).Parent;
    var txtCode = parent.FindControl("txtCode") as TextBox;
    var txtDesc = parent.FindControl("txtDesc") as TextBox;
    }


    -- bruce (sqlwork.com)

    Jeff wrote:
    > hi
    >
    > asp.net 2.0
    >
    > I have a GridView here with some controls in it's EmptyDataTemplate. I'm
    > wondering how I can get access to those controls. I've tryed using
    > FindControl, but that doesn't work because EmptyDataTemplate doesn't have
    > that method
    >
    > <EmptyDataTemplate>
    > <asp:TextBox ID="txtCode" runat="server"></asp:TextBox>
    > <asp:TextBox ID="txtDesc" runat="server"></asp:TextBox>
    > <asp:LinkButton ID="lbEmpty" OnClick="lbEmpty_Click" runat="server">Legg
    > til</asp:LinkButton>
    > </EmptyDataTemplate>
    >
    > (BTW, it is in the lbEmpty_Click method I'm trying to access the txtCode and
    > txtDesc textboxes. it's here the problem occur)
    >
    > Any suggestions?
    >
    >
     
    bruce barker, Nov 4, 2008
    #2
    1. Advertising

  3. EmptyDataTemplate controls

    when grid source has no data, you have the row from emptydataTemplate which is not placed in normal Rows collection but is nested in Control(0) of gridview (which is a ChildTable that comes from System.Web.Ui.Controls and it is a
    System.Web.UI.WebControls.Table

    in these situations you can get the gridviewRow this way:
    vb code
    dim dr as GridViewRow= gridview1.Controls(0).Controls(0)
    c# code
    GridViewRow dr= gridview1.Controls(0).Controls(0)

    Now you can use findControl with dr to get your controls:
    dr.FindControls("yourControlId")


    Have happy coding,
    Cimpy




    Jeff wrote:

    accessing control in EmptyDataTemplate
    04-Nov-08

    hi

    asp.net 2.0

    I have a GridView here with some controls in it's EmptyDataTemplate. I'm
    wondering how I can get access to those controls. I've tryed using
    FindControl, but that doesn't work because EmptyDataTemplate doesn't have
    that method

    <EmptyDataTemplate>
    <asp:TextBox ID="txtCode" runat="server"></asp:TextBox>
    <asp:TextBox ID="txtDesc" runat="server"></asp:TextBox>
    <asp:LinkButton ID="lbEmpty" OnClick="lbEmpty_Click" runat="server">Legg
    til</asp:LinkButton>
    </EmptyDataTemplate>

    (BTW, it is in the lbEmpty_Click method I'm trying to access the txtCode and
    txtDesc textboxes. it's here the problem occur)

    Any suggestions?

    Previous Posts In This Thread:

    On Tuesday, November 04, 2008 4:53 AM
    Jeff wrote:

    accessing control in EmptyDataTemplate
    hi

    asp.net 2.0

    I have a GridView here with some controls in it's EmptyDataTemplate. I'm
    wondering how I can get access to those controls. I've tryed using
    FindControl, but that doesn't work because EmptyDataTemplate doesn't have
    that method

    <EmptyDataTemplate>
    <asp:TextBox ID="txtCode" runat="server"></asp:TextBox>
    <asp:TextBox ID="txtDesc" runat="server"></asp:TextBox>
    <asp:LinkButton ID="lbEmpty" OnClick="lbEmpty_Click" runat="server">Legg
    til</asp:LinkButton>
    </EmptyDataTemplate>

    (BTW, it is in the lbEmpty_Click method I'm trying to access the txtCode and
    txtDesc textboxes. it's here the problem occur)

    Any suggestions?

    On Tuesday, November 04, 2008 9:46 AM
    bruce barker wrote:

    Re: accessing control in EmptyDataTemplate
    try:


    void lbEmpty_Click(Object sender, EventArgs e)
    {
    var parent = ((Control) sender).Parent;
    var txtCode = parent.FindControl("txtCode") as TextBox;
    var txtDesc = parent.FindControl("txtDesc") as TextBox;
    }


    -- bruce (sqlwork.com)

    Jeff wrote:


    Submitted via EggHeadCafe - Software Developer Portal of Choice
    SharePoint - Managing Unused or Archive sites automatically
    http://www.eggheadcafe.com/tutorial...5b-a2a8deb60cad/sharepoint--managing-unu.aspx
     
    Cesare Imperiali, Feb 9, 2010
    #3
    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. Shimon Sim
    Replies:
    2
    Views:
    6,051
  2. =?Utf-8?B?cm9kY2hhcg==?=

    Adding a control to EmptyDataTemplate

    =?Utf-8?B?cm9kY2hhcg==?=, Oct 17, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    408
    =?Utf-8?B?cm9kY2hhcg==?=
    Oct 17, 2006
  3. kbutterly
    Replies:
    1
    Views:
    351
    kbutterly
    Dec 6, 2006
  4. lax4u
    Replies:
    0
    Views:
    802
    lax4u
    Mar 13, 2008
  5. Lee Moore

    GridView EmptyDataTemplate Question

    Lee Moore, Jul 22, 2005, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    578
    Harolds
    Jul 22, 2005
Loading...

Share This Page