470,867 Members | 1,793 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,867 developers. It's quick & easy.

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?
Nov 4 '08 #1
1 7177
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?

Nov 4 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Vivek Sharma | last post: by
reply views Thread by rodchar | last post: by
3 posts views Thread by Nathan Sokalski | last post: by
8 posts views Thread by GaryDean | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.