473,748 Members | 10,539 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

hiding columns in Gridview with paging enabled

7 New Member
Hi,

I am programmaticall y binding gridview to a datatable. I want to hide 2 columns. I can be done by adding code in RowCreated event of gridview like

e.Row.Cells[0].Visible = false;
e.Row.Cells[5].Visible = false;

but after that paging is not working.
I tried another way by using gridview's column.Visible property
but its giving error
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

gvAllReports.Co lumns[1].Visible = false;
//gvAllReports.Co lumns[6].Visible = false;

Please guide me wat should I do
Dec 5 '09 #1
9 12092
sanjib65
102 New Member
Actually hiding columns can be done in Edit Template section. Not programmaticall y, the .NET Framework has assisted to do this.
You can select the textBox and in Properties make the Visble property false.
Dec 5 '09 #2
Frinavale
9,735 Recognized Expert Moderator Expert
Setting the visibility columns or cells in a GridView does not have any effect on the paging.

Please post the code that handles the GridView's paging so that we can see what's going wrong.


-Frinny
Dec 5 '09 #3
ally
7 New Member
Thnaks Frinny for help.
Here is the code.
Expand|Select|Wrap|Line Numbers
  1.   gvAllReports.DataSource = dt; //dt is DataTable
  2.         gvAllReports.DataBind();
  3.         gvAllReports.Columns[1].Visible = false;
  4.         gvAllReports.Columns[6].Visible = false;
  5.  
it gives error "Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index" even if I checked and rechecked the indexes of the columns.

-Ally
Dec 7 '09 #4
sanjib65
102 New Member
If you want to do that in code behind page it gives error!
I'm requesting Frinny to explain as it's beyond my knowledge :)
But it works if you go to the source view and change the boundfield properties. Like this:

Expand|Select|Wrap|Line Numbers
  1. <asp:BoundField DataField="LastName" HeaderText="LastName" 
  2.                                 SortExpression="LastName" Visible="false" />
  3.  
Likewise you can make Enable Paging true:

Expand|Select|Wrap|Line Numbers
  1.   <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
  2.                         DataKeyNames="EID" DataSourceID="SqlDataSource1" Width="293px" AllowPaging="true">
Dec 7 '09 #5
ally
7 New Member
Hey Sanji,

My datatable is getting bound at runtime. At design time there is no binding. Thats why I cannot add boundfield in source view.
this is my problem.

-Ally
Dec 7 '09 #6
ssnaik84
149 New Member
whats the column count of your datatable?
Dec 7 '09 #7
ally
7 New Member
Column count is 6. But I think thats not the problem because even I change column index to 1 or 0. Its giving me same error.
One more thing I tried to do is debug and checked the line to check column count, its showing 0, even after the gridview.DataBi nd().
I don't understand why the column count is showing 0.
Do I have to add that code to some other event?
Dec 7 '09 #8
ally
7 New Member
Hi all,
I got the solution.
I dynamically added bound fields.

Expand|Select|Wrap|Line Numbers
  1. foreach (DataColumn dc in dt.Columns) //dt is source datatable
  2.         {
  3.             BoundField bf = new BoundField();
  4.             bf.DataField = dc.ColumnName;
  5.             bf.HeaderText = dc.ColumnName;
  6.             gvAllReports.Columns.Add(bf); //gvAllReports is GridView
  7.         }
  8.  
  9.         gvAllReports.DataSource = dt;
  10.         gvAllReports.DataBind();
  11.                gvAllReports.Columns[1].Visible = false;
  12.         gvAllReports.Columns[6].Visible = false;
  13.  
Now its working properly. :) Thanks for your help

-Ally
Dec 7 '09 #9
rohit99452
1 New Member
Try this
just calculate the count
it works

protected void GridView1_RowDa taBound(object sender, GridViewRowEven tArgs e)
{
if(e.Row.Cells. Count>2)
{
e.Row.Cells[2].Visible = false;
}
}
Mar 22 '18 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2733
by: ck388 | last post by:
For some reason when I enable the callback feature of the gridview I still get a page refresh, that is it seems like there is a postback that occurs, not a callback which is just supposed to update not the whole page, but a portion of the page. Strangely enough the URL below http://beta.asp.net/QUICKSTARTV20/aspnet/doc/ctrlref/data/gridview.aspx (VB GridView Paging and Sorting Callbacks example)
0
1270
by: Samy | last post by:
Hi There, I have a grid view which has paging enabled in it. One of the colums is a check box and checkbox selections shows a subset of rows a user has selected from available rows. I need to update the dataset by checking the rows selected by a user. What is the best way to do that? I have paging enabled in the gridview and if the user selects some rows in the first page and a few rows in the second page, I save the ids in the...
1
2945
by: davidjgonzalez | last post by:
I have a GridView that has paging enabled. Each item (as defined in an ItemTemplate) includes several controls which have operations i would like to Atlas-enable. Everything is working well except when I page the GridView (the paging controllers are in the gridview's footer). The webpage doesnt scroll back to the top of the page, so when paging through the GridView the user is always looking at the last 4-5 items on the page. My current...
8
8535
by: AG | last post by:
ASP.NET 2.0, VS 2005 I have a gridview with paging enabled, bound to an objectdatasource. Both were dropped on to the page and configured via the wizards. Basically working as expected. The gridview's databind method is apparently called when the page is loaded as I have no code calling the databind method. How can I keep the gridview from databinding automatically and control it myself?
1
2312
by: DMC | last post by:
Hi, I have enabled paging in my gridview control and am now trying to work out how to programmatically access it. With my gridview i have an "Add" button which adds a new row to the gridview and underlying data source, and initialises values to null, except for primary key which is auto incremented in SQL Server. When this new row is added, i want to navigate to the page in the gridview containing the new addition (the last row), and...
9
15773
by: =?Utf-8?B?c3Jpbml2YXM=?= | last post by:
Hi All, Can anybody please help me, how to access all rows in a grid view if the paging is enabled? If gridview contains 100 rows and pagecount=10, then in the gridview.rows collection, i'm getting only those 10 rows which are displayed on the screen. But i want to access all the 100 rows in the code. Thanks in advance
2
13198
by: antonyliu2002 | last post by:
I've been googling for some time, and could not find the solution to this problem. I am testing the paging feature of gridview. I have a very simple web form on which the user can select a few fields to be included in the table, which is to be bound to the gridview. The web form looks like so (Don't worry about the stupidity of this web form for now.):
2
2907
by: =?Utf-8?B?SmF5IFBvbmR5?= | last post by:
Based on wether a row is selected in a GridView I need to HIDE the last two columns of a gridview. I do NOT need to make the cells invisible I want to hide the entire column. When I set the Visible property on the columns it causes the underlying ObjectDataSource to re-issue the Select statement. How can I hide these columns without double clutching the ODS Select?
2
3667
by: =?Utf-8?B?UGhpbCBKb2huc29u?= | last post by:
Hello, I have an asp.net 2.0 gridview with the paging enabled. I don't want to display the footer, but it always displays with the page numbers displayed. I have set the grid's showfooter to false and also tried to set the footerstyle height to 0px, but it always seems to show. Is there any way to hide the footer?
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8831
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9325
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8244
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.