<div mce_keep="true">Case two: the one that turned a little of my hairs grey, you don't have a control that fires an event you can trigger</div> <div mce_keep="true">
<EmptyDataTemplate>
<asp:TextBox
ID="txtInfo"
runat="server"
/>
</EmptyDataTemplate>
The Gridview 'gvInternalInfo' resides in a FormView 'fvVerslag'
Member
20 Points
4 Posts
GridView Control - EmptyDataTemplate - FindControl
Jan 09, 2009 05:56 AM|Cohete|LINK
I was strugling to find a TextBox which resides in the EmtyDataTemplate of a Gridview within a FormView
Finaly found a decent way to grab the control so I though I should share it because I didn't find the apropriate answer while searching the Internet
You have a TextBox in the EmtpyDataTemplate and a clickable Button
<
EmptyDataTemplate> <asp:TextBox ID="txtInfo" runat="server" /> <asp:Button ID="btn" runat="server" onclick="btn_Click" Text="Test" /></EmptyDataTemplate>
-- you can easily reference the TextBox in the button's click event
protected void btn_Click(object sender, EventArgs e){
Button
btn = (Button)sender; TextBox txtInfo = (TextBox)btn.NamingContainer.FindControl("txtInfo"); }as simple as that
<div mce_keep="true">Case two: the one that turned a little of my hairs grey, you don't have a control that fires an event you can trigger</div> <div mce_keep="true"><EmptyDataTemplate>
<asp:TextBox ID="txtInfo" runat="server" /></EmptyDataTemplate>
The Gridview 'gvInternalInfo' resides in a FormView 'fvVerslag'
here is the Gridview
<asp:GridView ID="gvInternalInfo" DataKeyNames="EVXMIID" runat="server" AutoGenerateColumns="False" DataSourceID="odsVerslagInternalInfo" SkinID="KanoGrid" ShowFooter="True" Caption="Interne Informatie"> <EmptyDataTemplate> <asp:TextBox ID="txtInfo" runat="server" /> </EmptyDataTemplate> <Columns> <asp:TemplateField HeaderText="Interne Informatie" SortExpression="INFO" ItemStyle-Wrap="true"> <FooterTemplate> <asp:TextBox ID="txtInfo" runat="server" Text='<%# Bind("INFO") %>' Width="650px" TextMode="MultiLine" Rows="5"></asp:TextBox></FooterTemplate> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("INFO") %>'></asp:Label></ItemTemplate> <ItemStyle Wrap="True" /> </asp:TemplateField> <asp:TemplateField HeaderText="Wie" SortExpression="UPDATEDBY"> <ItemTemplate> <asp:Label ID="Label2" runat="server" Text='<%# Bind("UPDATEDBY") %>'></asp:Label></ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Wanneer" SortExpression="DATEUPDATE"> <ItemTemplate> <asp:Label ID="Label3" runat="server" Text='<%# Bind("DATEUPDATE") %>'></asp:Label></ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>Now I needed the text of the txtInfo TextBox in the ItemUpdating event of fvVerslag
FindControl TextBox User Control find control EmptyDataTemplate
Tom
"Mark as Answer" if applicable
'Thoughts are not facts'
Contributor
2957 Points
922 Posts
Re: GridView Control - EmptyDataTemplate - FindControl
Jan 09, 2009 07:10 AM|Nemesis116|LINK
Thanks Cohete x)
Visit my blog
None
0 Points
1 Post
Re: GridView Control - EmptyDataTemplate - FindControl
May 05, 2009 09:17 PM|beetsj|LINK
Cohete,
Thanks for the helpful info. It worked for me!
BTW you can call FindControl on the GridViewRow directly instead of first referencing a cell.
regards
Jon