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

  • Home
  • SEARCH
  • 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 9143347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:59:59+00:00 2026-06-17T09:59:59+00:00

I have a usercontrol in Asp, that has a GridView, ‘AutoGenerateColumns=False. I must hide

  • 0

I have a usercontrol in Asp, that has a GridView, ‘AutoGenerateColumns=”False”.
I must hide or show a column according to a property of UC. How can I do that?

This is how I thought to do:

<asp:TemplateField HeaderText="<%=SelezionaColumnName  %>" HeaderStyle-Width="80px">

Note that here the headerText is not set to the public const string SelezionaColumnName but it renders just exactly as it is( in string), not the value but the name with <%= %>. I don’t know why, is this because of binding?

code behind:

public const string SelezionaColumnName = "Seleziona";

        public bool ShowSeleziona
        {
            set
            {
                grdMaterialiArt.Columns[GetColumnIndexByName(grdMaterialiArt, SelezionaColumnName)].Visible = value;
            }
        }

 protected int GetColumnIndexByName(GridView grid, string name)
        {
            foreach (DataControlField col in grid.Columns)
            {
                if (col.HeaderText.ToLower().Trim() == name.ToLower().Trim())
                {
                    return grid.Columns.IndexOf(col);
                }
            }

            return -1;
        }

Note: I must note use 0 index. Columns could be added before my column so I must identify uniquely the column. I went on identify by name approach as a TemplateField can not have an ID 😐
Hope I described the scenario well enough, I also search a lot around but did not found something similar.

  • 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-06-17T10:00:00+00:00Added an answer on June 17, 2026 at 10:00 am
     protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
        {
    
            try
            {
                DataTable dt = (DataTable ) GridView1.DataSource;
                if (!dt.Columns.Contains("COLLUMN_YOU_WANNA_HIDE")) return;
                int j = dt.Columns.IndexOf("COLLUMN_YOU_WANNA_HIDE");
                e.Row.Cells[j].Visible = false;
                e.Row.Cells[j].Width = 0;
            }
            catch (Exception)
            {
    
    
            }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UserControl in my Asp.net project that has a public property. I
I have an ASP.Net application that has a UserControl that needs to be rendered
I have a Todo List (an ASP.MVC UserControl) that for each row has the
I have an ASP.NET web form that has a container usercontrol that hosts several
I have a usercontrol in an asp web forms application that I am working
I have an ASP.NET usercontrol that implements the ValidationProperty attribute. This attribute successfully makes
I have an asp.net UserControl that writes HTML content from a SharePoint list to
I have a usercontrol that hides a div when a button is clicked. <asp:LinkButton
I have a partial view (UserControl) that implements a simple pager in my Asp.Net
I have a usercontrol in ASP.Net featuring a button that I use to postback.

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.