accessing control in EmptyDataTemplate

  • Thread starter Thread starter Jeff
  • Start date Start date
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?
 
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)
 
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
 
Back
Top