sony1464
asked on
hide data grid column
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
that's easy. just set the column's visible = false.
ASKER
nope that does not work...
i tried binding the datagrid to the dataset and then datagrid1.column(2).visibl e=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...
i tried binding the datagrid to the dataset and then datagrid1.column(2).visibl
should be datagrid1.Columns(2).Visib le = False. Column start from 0.
Weird. I always use it. Could you paste some test code here ?
Weird. I always use it. Could you paste some test code here ?
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).Visib le = False after the Columns.Add() line.
ASKER
ds1 = objconn.getdataset(strsql)
'ds1.Tables(0).Columns("PR SN_ID").Co lumnMappin g = MappingType.Hidden
ds1.Tables(0).Columns(0).C olumnName = " INDEX"
ds1.Tables(0).Columns(1).C olumnName = "ITEM NO."
ds1.Tables(0).Columns(2).C olumnName = "PERSON INDEX"
ds1.Tables(0).Columns(3).C olumnName = "POSITION"
ds1.Tables(0).Columns(4).C olumnName = "LAST NAME"
ds1.Tables(0).Columns(5).C olumnName = "FIRST NAME"
DataGrid1.DataSource = ds1
DataGrid1.DataBind()
DataGrid1.Columns(2).Visib le = 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...
'ds1.Tables(0).Columns("PR
ds1.Tables(0).Columns(0).C
ds1.Tables(0).Columns(1).C
ds1.Tables(0).Columns(2).C
ds1.Tables(0).Columns(3).C
ds1.Tables(0).Columns(4).C
ds1.Tables(0).Columns(5).C
DataGrid1.DataSource = ds1
DataGrid1.DataBind()
DataGrid1.Columns(2).Visib
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...
have you tried:
ds1.Tables(0).Columns(0).C olumnMappi ng = MappingType.Hidden
You can also try to set the width to 0 (as suggested in the same link)
ds1.Tables(0).Columns(0).C
You can also try to set the width to 0 (as suggested in the same link)
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!
dgrid.TableStyles("Name of your table").GridColumnStyles("
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!
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).Visib le = false will work because I have used it a lot.
you can set a breakpoint in DataGrid1.DataBind(), and check the
datagrid1.Columns.Count value. I am sure DataGrid1.Columns(2).Visib
do it in the html tab (aspx file):
<asp:BoundColumn DataField="PERSON INDEX" HeaderText="PERSON INDEX" Visible="False"></asp:Boun dColumn>
regards
<asp:BoundColumn DataField="PERSON INDEX" HeaderText="PERSON INDEX" Visible="False"></asp:Boun
regards
ASKER
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_Ro w" AllowPaging="True" PageSize="5">
<AlternatingItemStyle BackColor="#D8E4F8"></Alte rnatingIte mStyle>
<HeaderStyle Font-Size="Smaller" Font-Names="Verdana" Font-Bold="True" ForeColor="White" BackColor="#003399"></Head erStyle>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Button id="btnEdit" runat="server" Font-Size="X-Small" Height="19px" Text="Edit" CommandName="Edit"></asp:B utton>
</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"></Page rStyle>
</asp:datagrid></TD>
1) ds1.Tables(0).Columns(VEHI CLE 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).C olumnName = "VEHICLE INDEX"
ds1.Tables(0).Columns(1).C olumnName = "ITEM NO."
ds1.Tables(0).Columns(2).C olumnName = "PERSON INDEX"
ds1.Tables(0).Columns(3).C olumnName = "POSITION"
ds1.Tables(0).Columns(4).C olumnName = "LAST NAME"
ds1.Tables(0).Columns(5).C olumnName = "FIRST NAME"
Dim value As String = ds1.Tables(0).Columns(2).C olumnName
Dim i As Integer
For i = 0 To ds1.Tables(0).Columns.Coun t - 1
Dim objbc As New BoundColumn
objbc.DataField = ds1.Tables(0).Columns(i).C olumnName
objbc.HeaderText = ds1.Tables(0).Columns(i).C olumnName
If objbc.DataField = ds1.Tables(0).Columns("VEH ICLE INDEX").ColumnName Or objbc.DataField = ds1.Tables(0).Columns("PER SON INDEX").ColumnName Then
objbc.Visible = False
End If
DataGrid1.Columns.Add(objb c)
Next
DataGrid1.DataSource = ds1.Tables(0)
DataGrid1.DataBind()
Please help me get this working.
Thank you
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_Ro
<AlternatingItemStyle BackColor="#D8E4F8"></Alte
<HeaderStyle Font-Size="Smaller" Font-Names="Verdana" Font-Bold="True" ForeColor="White" BackColor="#003399"></Head
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Button id="btnEdit" runat="server" Font-Size="X-Small" Height="19px" Text="Edit" CommandName="Edit"></asp:B
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Button id="btnDelete" runat="server" Height="19px" Font-Size="X-Small" Text="Delete" CommandName="Delete"></asp
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle Mode="NumericPages"></Page
</asp:datagrid></TD>
1) ds1.Tables(0).Columns(VEHI
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).C
ds1.Tables(0).Columns(1).C
ds1.Tables(0).Columns(2).C
ds1.Tables(0).Columns(3).C
ds1.Tables(0).Columns(4).C
ds1.Tables(0).Columns(5).C
Dim value As String = ds1.Tables(0).Columns(2).C
Dim i As Integer
For i = 0 To ds1.Tables(0).Columns.Coun
Dim objbc As New BoundColumn
objbc.DataField = ds1.Tables(0).Columns(i).C
objbc.HeaderText = ds1.Tables(0).Columns(i).C
If objbc.DataField = ds1.Tables(0).Columns("VEH
objbc.Visible = False
End If
DataGrid1.Columns.Add(objb
Next
DataGrid1.DataSource = ds1.Tables(0)
DataGrid1.DataBind()
Please help me get this working.
Thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sony dont reply to my last post, dont know how is going