Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > accessing control in EmptyDataTemplate

Reply
Thread Tools

accessing control in EmptyDataTemplate

 
 
Jeff
Guest
Posts: n/a
 
      11-04-2008
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?


 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      11-04-2008
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?
>
>

 
Reply With Quote
 
 
 
 
Cesare Imperiali
Guest
Posts: n/a
 
      02-09-2010
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/tutorials...aging-unu.aspx
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to CommandArgument of LinkButton inside EmptyDataTemplate? lax4u ASP .Net 0 03-13-2008 09:13 PM
Another basic newbie question: How to get the empty EmptyDataTemplate to act like the InsertItemTemplate kbutterly ASP .Net 1 12-06-2006 05:55 PM
Adding a control to EmptyDataTemplate =?Utf-8?B?cm9kY2hhcg==?= ASP .Net 0 10-17-2006 04:08 PM
GridView EmptyDataTemplate - how to get controls Shimon Sim ASP .Net 2 09-23-2006 09:16 PM
GridView EmptyDataTemplate Question Lee Moore ASP .Net Web Controls 2 07-22-2005 05:28 PM



Advertisments