Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. addressing a GridView column

addressing a GridView column

Scheduled Pinned Locked Moved ASP.NET
helpcssdatabasecsharpvisual-studio
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 2942716
    wrote on last edited by
    #1

    Hi, This is my first question posted here so please go easy on me :) I've been searching around and trying all sorts of things to solve this problem but still no luck... after I bind the data to the wanted GridView, I can not address a specific column that I want to set to visible = false. I keep getting this error: "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index". Debugging shows that Grid has data and it is not empty, so I do not see a reason for this to happen. here is an example code and the stack trace:

    private void GetUpdated()
    {
        DataSet ds = new DataSet();
        DataTable dt = new DataTable();
        dt = myData.RetrieveData("db\_GetCaseLastUpdate").Tables\[0\];
        dt.Columns.Remove("IncidentId");
        dt.Columns\[1\].ColumnName = "Last Modified";
        grid\_Update.DataSource = dt;
        grid\_Update.DataBind();
        grid\_Update.Columns\[0\].Visible = false;  <-- sorce error
    }
    

    Stack Trace: [ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index] System.Collections.ArrayList.get_Item(Int32 index) +2880797 System.Web.UI.StateManagedCollection.System.Collections.IList.get_Item(Int32 index) +9 System.Web.UI.WebControls.DataControlFieldCollection.get_Item(Int32 index) +5 _Default.GetUpdated() in c:\Documents and Settings\customerservices\My Documents\Visual Studio 2005\WebSites\AjaxControlToolkitWebSite1\Default.aspx.cs:81 _Default.Page_Load(Object sender, EventArgs e) in c:\Documents and Settings\customerservices\My Documents\Visual Studio 2005\WebSites\AjaxControlToolkitWebSite1\Default.aspx.cs:26 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33 System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +47 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436 Also, I can't seem to find a way to change a column's width. I hope this is the right forum for this question... TIA for your help!!!

    S 1 Reply Last reply
    0
    • U User 2942716

      Hi, This is my first question posted here so please go easy on me :) I've been searching around and trying all sorts of things to solve this problem but still no luck... after I bind the data to the wanted GridView, I can not address a specific column that I want to set to visible = false. I keep getting this error: "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index". Debugging shows that Grid has data and it is not empty, so I do not see a reason for this to happen. here is an example code and the stack trace:

      private void GetUpdated()
      {
          DataSet ds = new DataSet();
          DataTable dt = new DataTable();
          dt = myData.RetrieveData("db\_GetCaseLastUpdate").Tables\[0\];
          dt.Columns.Remove("IncidentId");
          dt.Columns\[1\].ColumnName = "Last Modified";
          grid\_Update.DataSource = dt;
          grid\_Update.DataBind();
          grid\_Update.Columns\[0\].Visible = false;  <-- sorce error
      }
      

      Stack Trace: [ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index] System.Collections.ArrayList.get_Item(Int32 index) +2880797 System.Web.UI.StateManagedCollection.System.Collections.IList.get_Item(Int32 index) +9 System.Web.UI.WebControls.DataControlFieldCollection.get_Item(Int32 index) +5 _Default.GetUpdated() in c:\Documents and Settings\customerservices\My Documents\Visual Studio 2005\WebSites\AjaxControlToolkitWebSite1\Default.aspx.cs:81 _Default.Page_Load(Object sender, EventArgs e) in c:\Documents and Settings\customerservices\My Documents\Visual Studio 2005\WebSites\AjaxControlToolkitWebSite1\Default.aspx.cs:26 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33 System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +47 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436 Also, I can't seem to find a way to change a column's width. I hope this is the right forum for this question... TIA for your help!!!

      S Offline
      S Offline
      Sam M
      wrote on last edited by
      #2

      follow the below: 1.

      for (int index = 0; index < this.grid_Update.Columns.Count; index++)
      {
      if (this.grid_Update.Columns[index].HeaderText == "SomeHeader")
      this.grid_Update.Columns[index].Visible = false;
      }

      2. "SomeHeader" is nothing but the column header.

      Regards n Thks Sam.M

      U 1 Reply Last reply
      0
      • S Sam M

        follow the below: 1.

        for (int index = 0; index < this.grid_Update.Columns.Count; index++)
        {
        if (this.grid_Update.Columns[index].HeaderText == "SomeHeader")
        this.grid_Update.Columns[index].Visible = false;
        }

        2. "SomeHeader" is nothing but the column header.

        Regards n Thks Sam.M

        U Offline
        U Offline
        User 2942716
        wrote on last edited by
        #3

        Thanks Sam, for the quick and effective reply!!! :-D

        S 1 Reply Last reply
        0
        • U User 2942716

          Thanks Sam, for the quick and effective reply!!! :-D

          S Offline
          S Offline
          Sam M
          wrote on last edited by
          #4

          You're most welcome.

          Regards n Thks Sam.M

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups