Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

hide data grid column

Posted on 2004-09-18
17
Medium Priority
?
362 Views
Last Modified: 2010-05-18

I am programming using asp.net and vb.net .I am populating a datagrid from from data set and i would like to hide a column in the datagrid..How do i do that

0
Comment
Question by:sony1464
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +3
17 Comments
 
LVL 7

Expert Comment

by:jackiechen858
ID: 12091407
that's easy. just set the column's visible = false.
0
 
LVL 3

Author Comment

by:sony1464
ID: 12091526
nope that does not work...

i tried binding the datagrid to the dataset and then datagrid1.column(2).visible=false.  It says that the column value is out of range. i don't know why...when the datagrid come up on the screen it shows up 5 colums...
0
 
LVL 7

Expert Comment

by:jackiechen858
ID: 12091557
should be datagrid1.Columns(2).Visible = False.   Column start from 0.

Weird. I always use it. Could you paste some test code here ?
0
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 7

Expert Comment

by:jackiechen858
ID: 12091564
maybe you set the columns not in the aspx page, but in the aspx.vb code? like datagrid1.Columns.add()... . Then you need to put datagrid1.Columns(2).Visible = False after the Columns.Add() line.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 12091618
0
 
LVL 3

Author Comment

by:sony1464
ID: 12091691
       ds1 = objconn.getdataset(strsql)
        'ds1.Tables(0).Columns("PRSN_ID").ColumnMapping = MappingType.Hidden
        ds1.Tables(0).Columns(0).ColumnName = " INDEX"
        ds1.Tables(0).Columns(1).ColumnName = "ITEM NO."
        ds1.Tables(0).Columns(2).ColumnName = "PERSON INDEX"
        ds1.Tables(0).Columns(3).ColumnName = "POSITION"
        ds1.Tables(0).Columns(4).ColumnName = "LAST NAME"
        ds1.Tables(0).Columns(5).ColumnName = "FIRST NAME"
        DataGrid1.DataSource = ds1
        DataGrid1.DataBind()
        DataGrid1.Columns(2).Visible =  false

Jackiechen858- this is the code i am presently trying.

emoreaU- As suggested in the article, i wrote that line of code as shown in the commented line above. that did not hide the column too...


0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 12091698
have you tried:
ds1.Tables(0).Columns(0).ColumnMapping = MappingType.Hidden

You can also try to set the width to 0 (as suggested in the same link)
0
 
LVL 7

Expert Comment

by:J_Mak
ID: 12091792
Here's how it should be done:

dgrid.TableStyles("Name of your table").GridColumnStyles("Name of the column").Width = 0

You can also find great examples of other different but neat tricks you can do to your datagrid in this link:

http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#Top

It's pretty cool. I've used it everywhere in my software and it's extremely useful.

Hope that helps!
0
 
LVL 7

Expert Comment

by:jackiechen858
ID: 12093396
your code only show the datatable has 6 columns, didn't tell us how many columns in the datagrid. could you paste your datagrid1 definition in the aspx file?

you can set a breakpoint in DataGrid1.DataBind(), and check the
datagrid1.Columns.Count value. I am sure  DataGrid1.Columns(2).Visible =  false will work because I have used it a lot.
0
 
LVL 10

Expert Comment

by:EBatista
ID: 12101099
do it in the html tab (aspx file):

<asp:BoundColumn DataField="PERSON INDEX" HeaderText="PERSON INDEX" Visible="False"></asp:BoundColumn>

regards
0
 
LVL 3

Author Comment

by:sony1464
ID: 12278209
Hello all,

            i am still having this problem. i have tried a lot of thins and nothing works as i wish. I have pasted the datagrid definition below.
           

<asp:datagrid id="DataGrid1" runat="server" Width="735px" BackColor="#D8E4F8" Height="138px" Font-Size="Smaller" BorderColor="Black" BorderStyle="Solid" OnEditCommand="edit_Row" OnDeleteCommand="Delete_Row" AllowPaging="True" PageSize="5">
 
   <AlternatingItemStyle BackColor="#D8E4F8"></AlternatingItemStyle>
<HeaderStyle Font-Size="Smaller" Font-Names="Verdana" Font-Bold="True" ForeColor="White" BackColor="#003399"></HeaderStyle>
<Columns>
 <asp:TemplateColumn>
    <ItemTemplate>
        <asp:Button id="btnEdit" runat="server" Font-Size="X-Small" Height="19px" Text="Edit" CommandName="Edit"></asp:Button>
   </ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
      <ItemTemplate>
           <asp:Button id="btnDelete" runat="server" Height="19px" Font-Size="X-Small" Text="Delete" CommandName="Delete"></asp:Button>
       </ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle Mode="NumericPages"></PagerStyle>
</asp:datagrid></TD>


1) ds1.Tables(0).Columns(VEHICLE INDEX).ColumnMapping = MappingType.Hidden

This did not gide any of the columns

2) for setting the width=0 i have to include datagrid table style. what namespace is it under. can it be included un web forms.


3)I tried the following setting autogenerated column =true then it hides the columns i want to but also duplicate columns with all the columns visible. that means if  my dataset has 6 columns and i want show 4 and hide 2. it correctly shows the four but it also displays another 6 columns. Then i triend autogenerated column =false. here it displays 4 columns out of 6. exactly the way i want. but  when i try to edit the entries...the invisible commn is not recognized as one of the columns.

         ds1.Tables(0).Columns(0).ColumnName = "VEHICLE INDEX"
        ds1.Tables(0).Columns(1).ColumnName = "ITEM NO."
        ds1.Tables(0).Columns(2).ColumnName = "PERSON INDEX"
        ds1.Tables(0).Columns(3).ColumnName = "POSITION"
        ds1.Tables(0).Columns(4).ColumnName = "LAST NAME"
        ds1.Tables(0).Columns(5).ColumnName = "FIRST NAME"
        Dim value As String = ds1.Tables(0).Columns(2).ColumnName

        Dim i As Integer
        For i = 0 To ds1.Tables(0).Columns.Count - 1
            Dim objbc As New BoundColumn
            objbc.DataField = ds1.Tables(0).Columns(i).ColumnName
            objbc.HeaderText = ds1.Tables(0).Columns(i).ColumnName
            If objbc.DataField = ds1.Tables(0).Columns("VEHICLE INDEX").ColumnName Or objbc.DataField = ds1.Tables(0).Columns("PERSON INDEX").ColumnName Then
                objbc.Visible = False
            End If
            DataGrid1.Columns.Add(objbc)
        Next

        DataGrid1.DataSource = ds1.Tables(0)
        DataGrid1.DataBind()

Please help me get this working.

Thank you

0
 
LVL 10

Accepted Solution

by:
EBatista earned 400 total points
ID: 12288500
the easiest way is define the datagrig columns in the html code and set the desired column as not visible:
(with autogenerated column set to false)

<asp:BoundColumn DataField="PERSON INDEX" HeaderText="PERSON INDEX" Visible="False"></asp:BoundColumn>

regards
0
 
LVL 10

Expert Comment

by:EBatista
ID: 12500562
sony dont reply to my last post, dont know how is going
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question