addressing a GridView column
-
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!!!
-
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!!!
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
-
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
Thanks Sam, for the quick and effective reply!!! :-D
-
Thanks Sam, for the quick and effective reply!!! :-D