accessing control in EmptyDataTemplate

J

Jeff

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?
 
B

bruce barker

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)
 
C

Cesare Imperiali

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:

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?

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top