Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6246211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:38:45+00:00 2026-05-24T12:38:45+00:00

I have formview control. Inside formview control their is one gridview. In gridview i

  • 0

I have formview control. Inside formview control their is one gridview. In gridview i have FooterTemplate(In footertemplate i have textbox control to add text)to add text. To find that control i have written code as follows:

 GridView mygridview = (GridView)FVAddCustomer.FindControl("mygridview");
TextBox txtFName1 = (TextBox)mygridview.FooterRow.FindControl("txtFName1");

Is this right or any other way? because when i find textbox value then its getting null?
Please help me?

  <asp:GridView ID="mygridview" runat="server" AutoGenerateColumns="False" ShowFooter="True" BackColor="White" BorderColor="#336666" BorderWidth="3px" CellPadding="4" GridLines="Horizontal" BorderStyle="Double" Width="100%" OnRowEditing="mygridview_RowEditing" OnRowCancelingEdit="mygridview_RowCancelingEdit" OnRowUpdating="mygridview_RowUpdating" Visible="false">
       <FooterStyle BackColor="White" ForeColor="#333333" />
       <PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
       <SelectedRowStyle BackColor="#339966" ForeColor="White" Font-Bold="True" />
       <HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
       <Columns>
          <asp:TemplateField HeaderText="First Name">
             <ItemTemplate>
                 <asp:Label ID="lblFName1" runat="server" Text='<%#Eval("FirstName")%>'></asp:Label>
             </ItemTemplate>
             <EditItemTemplate>
                  <asp:TextBox ID="txtFName1Edit" runat="server" Width="90px"></asp:TextBox>
            </EditItemTemplate>
            <FooterTemplate>
               <asp:TextBox ID="txtFName1" runat="server" Width="90px"></asp:TextBox>
            </FooterTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Edit">
            <ItemTemplate>
               <asp:LinkButton ID="lnkEdit" runat="server" Text="Edit" CommandName="Edit" CausesValidation="false" OnClick="lnkEdit_Click"></asp:LinkButton>
            </ItemTemplate>
            <EditItemTemplate>
              <asp:LinkButton ID="lnkUpdate" runat="server" Text="Update" CommandName="Update"></asp:LinkButton>
              <asp:LinkButton ID="lnkCancel" runat="server" Text="cancel" CommandName="Cancel"></asp:LinkButton>
            </EditItemTemplate>
            <FooterTemplate>
                <asp:LinkButton ID="lnkAdd" runat="server" Text="Add" CommandName="Add" Width="90px" OnClick="lnkAdd_Click"></asp:LinkButton>
            </FooterTemplate>
         </asp:TemplateField>

Thank you.
Asp.net C#

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:38:46+00:00Added an answer on May 24, 2026 at 12:38 pm

    From the comments:

    Do you have called FormView.DataBind/GridView.DataBind before?

    Remember also that FormView has 3 different FormViewModes. If it is currently in Edit-Mode and the GridView is in ReadOnly ItemTemplate, then you cannot access it.

    Try this to get the TextBox from the LinkButton’s click-event handler:

    private void lnkadd_Click(object sender, System.EventArgs e)
    {
        var footer = (GridViewRow)((WebControl)sender).NamingContainer;
        var txtFName1 = (TextBox)footer.FindControl("footer");
    }
    

    Edit: if this does not work, you can try to handle the GridView’s RowCommand:

    protected void mygridview_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Add") {
            var txtFName1 = (TextBox)((GridView)sender).FooterRow.FindControl("txtFName1");
        }
    }
    

    Edit2:

    You should bind your GridView to it’s DataSource only if !IsPostBack. The best place to do this is in the FormView’s DataBound Event:

    protected void FormView1_DataBound(object sender, System.EventArgs e)
    {
        switch (FormView1.CurrentMode) {
            case FormViewMode.Insert:
                var mygridview = (GridView)((FormView)sender).FindControl("mygridview");
                //Bind your GridView here'
                break;
        }
    }
    

    On this way you ensure that the GridView will be rebound automatically when the FormView gets databound. If the FormView changes it’s mode to Insert, you have to DataBind it even if the DataSource is null!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings! I have a Repeater control that's using an XmlDataSource control. <asp:FormView id=myFormView runat=server
I have a DLL that contain a user control inside, in the Web Form
I have a checkbox and a panel inside of a FormView control, and I
I have a FormView control with Two text Boxes. Data source for the Controls
By default the FormView control creates html like : ID <asp:TextBox ID=IdTextBox runat=server Text='<%#
I have a FormView control in an ASP.NET 2.0 app. I've got the database
I have an asp:FormView control bound to a datasource. Everything is working fine. If
I have an asp:FormView on a control (in an ascx file) which is loaded
In my application I have TextBox in a FormView bound to a LinqDataSource like
I need to find a value in a TextBox, contained within a FormView which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.