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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:52:01+00:00 2026-05-24T01:52:01+00:00

I’m trying to get a column in my unbound gridview to be invisible, specifically

  • 0

I’m trying to get a column in my unbound gridview to be invisible, specifically the id. I’m binding the grid with ADO.net, so I cant just set the tag in the html code to invisible. Here is some code…

    protected void btn_search_Click(object sender, EventArgs e)
    {
        SqlConnection cs = new SqlConnection("Data Source=WILSON-PC; Initial Catalog=KamManOnline; Integrated Security=TRUE");



        SqlDataAdapter da = new SqlDataAdapter();
        DataSet ds = new DataSet();

        da.SelectCommand = new SqlCommand("SELECT oid, Supplier, DepartmentA, DepartmentB, DepartmentC, OrderNumber, CONVERT(varchar(10), PORecieptDate, 101) AS PORecieptDate, CONVERT(varchar(10), ProductRecieved, 101) AS ProductRecieved, CONVERT(varchar(10),POEntryDate, 101) AS POEntryDate FROM tbl_OrderD WHERE (Supplier = @Supplier OR @Supplier IS NULL) AND (DepartmentA = @DepartmentA OR @DepartmentA IS NULL) AND (OrderNumber = @OrderNumber OR @OrderNumber IS NULL) AND (PORecieptDate BETWEEN @FromA AND @ToA OR (@FromA IS NULL AND @ToA IS NULL)) AND (ProductRecieved BETWEEN @FromB AND @ToB OR (@FromB IS NULL AND @ToB IS NULL)) AND (POEntryDate BETWEEN @FromC AND @ToC OR (@FromC IS NULL AND @ToC IS NULL))", cs);



        if (!chk_Suppliers.Checked) da.SelectCommand.Parameters.Add("@Supplier", SqlDbType.VarChar).Value = ddl_SupplierView.Text.ToString();
        else da.SelectCommand.Parameters.Add("@Supplier", SqlDbType.VarChar).Value = DBNull.Value;

        if (!chk_Departments.Checked) da.SelectCommand.Parameters.Add("@DepartmentA", SqlDbType.VarChar).Value = ddl_DepartmentView.Text.ToString();
        else da.SelectCommand.Parameters.Add("@DepartmentA", SqlDbType.VarChar).Value = DBNull.Value;

        if (txt_orderNumView.Text != "") da.SelectCommand.Parameters.Add("@OrderNumber", SqlDbType.VarChar).Value = txt_orderNumView.Text.ToString();
        else da.SelectCommand.Parameters.Add("@OrderNumber", SqlDbType.VarChar).Value = DBNull.Value;

        if (txt_PORecievedFrom.Text != "" && txt_PORecievedTo.Text != "")
        {
            da.SelectCommand.Parameters.Add("FromA", SqlDbType.SmallDateTime).Value = txt_PORecievedFrom.Text.ToString();
            da.SelectCommand.Parameters.Add("ToA", SqlDbType.Date).Value = txt_PORecievedTo.Text.ToString();
        }

        else
        {
            da.SelectCommand.Parameters.Add("FromA", SqlDbType.Date).Value = DBNull.Value;
            da.SelectCommand.Parameters.Add("ToA", SqlDbType.Date).Value = DBNull.Value;
        }

        if (txt_ProductRecievedFrom.Text != "" && txt_ProductRecievedTo.Text != "")
        {
            da.SelectCommand.Parameters.Add("FromB", SqlDbType.Date).Value = txt_PORecievedFrom.Text;
            da.SelectCommand.Parameters.Add("ToB", SqlDbType.Date).Value = txt_PORecievedTo.Text;
        }

        else
        {
            da.SelectCommand.Parameters.Add("FromB", SqlDbType.Date).Value = DBNull.Value;
            da.SelectCommand.Parameters.Add("ToB", SqlDbType.Date).Value = DBNull.Value;
        }

        if (txt_POEntryFrom.Text != "" && txt_poEntryTo.Text != "")
        {
            da.SelectCommand.Parameters.Add("FromC", SqlDbType.Date).Value = txt_PORecievedFrom.Text;
            da.SelectCommand.Parameters.Add("ToC", SqlDbType.Date).Value = txt_PORecievedTo.Text;
        }

        else
        {
            da.SelectCommand.Parameters.Add("FromC", SqlDbType.Date).Value = DBNull.Value;
            da.SelectCommand.Parameters.Add("ToC", SqlDbType.Date).Value = DBNull.Value;
        }

        ds.Clear();

        da.Fill(ds);

        gv_search.DataSource = ds.Tables[0];
        gv_search.DataBind();


    }

this is your basic good old ASP.net search function. However, in this gridview I enable selecting like this…

    protected void gv_search_SelectedIndexChanged(object sender, EventArgs e)
    {

        Response.Redirect("selectedOrder.aspx?oid=" + gv_search.SelectedValue.ToString());
    }

I know I can set the oid to be the datakey tab. However, I want to make this invisible. I have tried this method here…

    protected void gv_search_RowCreated(object sender, GridViewRowEventArgs e)
    {
        gv_search.Columns[0].Visible = false;
    }

It gave me this error…

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Does anyone know how to do this? Thanks

  • 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-24T01:52:02+00:00Added an answer on May 24, 2026 at 1:52 am

    Declare the columns you want displayed inside the aspx file. Tell the grid to not generate columns using the AutoGenerateColumns="False" property.

    <asp:DataGrid id="DataGrid1" 
       runat="server" CssClass="grid" 
       AutoGenerateColumns="False">
       <Columns>
          <asp:BoundColumn 
             DataField="OrderID" ReadOnly="True" 
             HeaderText="Order ID" />
          <asp:BoundColumn 
             DataField="ShipName" HeaderText="Ship to" 
             ReadOnly="True" />
          <asp:BoundColumn 
             DataField="ShipCountry" HeaderText="Country" 
             ReadOnly="True" />
         <asp:BoundColumn 
             DataField="ShipCountry" HeaderText="Country" 
             Visible="False" />
       </Columns>
    </asp:DataGrid>
    

    Set the desired columns to Visible="False".

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Specifically, suppose I start with the string string =hello \'i am \' me And
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.