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 7598269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:21:58+00:00 2026-05-30T22:21:58+00:00

I am having an issue with the behavior of a GridView between post backs.

  • 0

I am having an issue with the behavior of a GridView between post backs.

The real problem comes from a TemplateField I define in the markup at column[0] with a child CheckBox control. Things work fine for the first, and second search executions. However, at some point between the second execution and anything that causes a post back there after, I lose the contents of the TemplateField.

Its only the the contents of the column and not the whole column itself that gets removed. The TemplateField is present in the source and shows a formated column at position 0 of the table.

CODE:

protected void ExecuteSearch(object sender, EventArgs e)
{
    if (lb_SelectedFields.Items.Count == 0) { return; } //if no selected fields

    //Generates custom SQL query based on user inputs and column Selections
    BuildQuery(); // sets txbSqlText.Text = to the SQL string

    DataTable Table = SqlAdapter.Select(new System.Data.SqlClient.SqlCommand(txbSqlText.Text));

    for (int i = gv_SearchResults.Columns.Count - 1; i > 0; i--) 
    { gv_SearchResults.Columns.RemoveAt(i); } //removes all the columns except[0]

    foreach (ListItem Item in lb_SelectedFields.Items) //adds all the user defined columns
    {
        //Column object that is able to find the column definition
        Column Col = ColumnsBasedOnFocus.FindColumName(Item.Value); 

        if (Col.Type == "HyperLink") { gv_SearchResults.Columns.Add(CreateHyperLinkField(Col)); }
        else { gv_SearchResults.Columns.Add(CreateBoundColumn(Col, true)); } //true is if the column is visable
    }

    gv_SearchResults.DataSource = Table;
    gv_SearchResults.DataBind();
}

ASP.NET:

<asp:GridView ID="gv_SearchResults" runat="server" GridLines="None" CellSpacing="0"
    CellPadding="0" AutoGenerateColumns="false" CssClass="TABLE_LIGHTBLUE" Width="100%">
    <HeaderStyle CssClass="TABLE_LIGHTBLUE_HEADERROW" />
    <Columns>
        <asp:TemplateField ItemStyle-Width="30" ItemStyle-Wrap="false">
            <HeaderTemplate>
                <center>
                    <asp:Button ID="btn_SelectAll" runat="server" OnClick="SelectAll" Text="All" CssClass="TEXT_SMALL" />
                    <asp:CheckBox ID="chk_Placeholder" runat="server" Visible="false" /></center>
            </HeaderTemplate>
            <ItemTemplate>
                <center>
                    <asp:CheckBox ID="chk_Select" runat="server" Visible="true" />
                    <asp:Label ID="lbl_AssetGID" runat="server" Visible="false" Text='<%# Bind("i_GID") %>' /></center>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
  • 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-30T22:21:59+00:00Added an answer on May 30, 2026 at 10:21 pm

    Found a link that describes a similar situation.

    https://connect.microsoft.com/VisualStudio/feedback/details/104994/templatefield-in-a-gridview-doesnt-have-its-viewstate-restored-when-boundfields-are-inserted#details

    They describe a bug in ASP.Net code that fails to properly manage view states with template fields in dynamically generated grid views.

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

Sidebar

Related Questions

I've been having the issue from here: Sharepoint issue, selective behavior? and I think
I am currently having a strange issue with an application migrated from rails 2.3.8
I'm having a wee issue with a double margin appearing between <div> 's. It
I'm having an issue reading from a java input stream. I have a buffer
I'm having a bit of an issue getting some stylesheet behavior that I want.
Having an issue with random individuals trying to access an intranet site with a
Having an issue here that I have tried everything I can think of but
The issue I'm having is issue with is I'm trying to get the paintComponent
I'm having an issue with a query that currently uses LEFT JOIN weblog_data AS
I'm having an issue with my regex. I want to capture <% some stuff

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.