473,394 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

datagrid width

Hello all,
I have searched the internet for this but can't find a working solution.
I have a datagrid in a web appl with a bound column. Filled with data from a
sql table. Works fine.
I want to hide the column but preserve the value because I need it in the
postback. Several 'solutions' said to set the column width and whatever. It
all does not work. It comes down to the fact that the table in html
automatically widens a column to fit the content, even if u set the width to
zero.
A possible solution would be to put the boundcolumn in a <span> and put a
'overflow: hidden' in it. Testing this outside vb.net with html I had that
working.
But how do I put a span around the bound column using vb.net? Do I do that
in the html tab? If I do I get errors.
Looking forward to a working solution.
Thanx
Frank
Nov 20 '05 #1
7 1120
Hi Frank,

Why do you not use the dataset(datatable) method and keeps the data you want
to preserve just in a Session, yesterday I made a sample for Ruca, it is not
direct your question but maybe you can use it as well, because it shows how
to make only showable columns?

The challenge was to use a handmade datatable, however doing that it did not
want to set the datakeyfield as not editable, so I had to do it in this way,
which maybe you can use now as I assume.

Cor
\\\\In the HTML page
<Columns>
<asp:EditCommandColumn ButtonType="PushButton" UpdateText="Update"
CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
<asp:BoundColumn DataField="A"></asp:BoundColumn>
<asp:BoundColumn DataField="B"></asp:BoundColumn>
<asp:BoundColumn DataField="C"></asp:BoundColumn>
</Columns>
///
\\\
Dim dt As New DataTable("Ruca")
Private Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
For i As Integer = 0 To 2
Dim dc As New DataColumn(Chr(i + 65))
dt.Columns.Add(dc)
Next
For i As Integer = 0 To 9
dt.Rows.Add(dt.NewRow)
For y As Integer = 0 To dt.Columns.Count - 1
dt.Rows(i)(y) = Chr(i + 48)
Next
Next

'the begin is making a table here it starts
DataGrid1.DataSource = dt
DataGrid1.DataKeyField = dt.Columns(0).ColumnName
DirectCast(DataGrid1.Columns(1), BoundColumn).ReadOnly = True
DataGrid1.DataBind()
Session.Item("dt") = dt
Else
dt = DirectCast(Session.Item("dt"), DataTable)
DataGrid1.DataSource = dt
DirectCast(DataGrid1.Columns(1), BoundColumn).ReadOnly = True
DataGrid1.DataKeyField = dt.Columns(0).ColumnName
End If
End Sub
Private Sub DataGrid1_CancelCommand1(ByVal source _
As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) _
Handles DataGrid1.CancelCommand
DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_EditCommand1(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) _
Handles DataGrid1.EditCommand
DataGrid1.EditItemIndex = e.Item.ItemIndex
DataGrid1.DataBind()
End Sub

Private Sub DataGrid1_UpdateCommand(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) _
Handles DataGrid1.UpdateCommand
Dim dv As New DataView(dt)
dv.RowFilter = dt.Columns(0).ColumnName & "=" _
& DataGrid1.DataKeys(e.Item.ItemIndex).ToString()
dv(0)(1) = DirectCast(e.Item.Cells(2).Controls(0), TextBox).Text()
dv(0)(2) = DirectCast(e.Item.Cells(3).Controls(0), TextBox).Text
Session.Item("dt") = dt
End Sub
End Class
///
Nov 20 '05 #2
It works that setting BoundColumn's Visible property to "False" .
Nov 20 '05 #3
Set BoundColumn's Visible property to false.
Nov 20 '05 #4
then the data is not sent back in the postback.

"rulinHong" <an*******@discussions.microsoft.com> wrote in message
news:32**********************************@microsof t.com...
Set BoundColumn's Visible property to false.

Nov 20 '05 #5
Cor, I thought about that. But lets be realistic, isn't there a lot simpler
solution to this problem? I can't be the first to have this problem.
Thanx anyway
Frank

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:ew**************@TK2MSFTNGP09.phx.gbl...
Hi Frank,


[clipped]
Nov 20 '05 #6
Hi Frank,

When you look at my sample, than I think you can make from the column you
want to make non visable a datatable, you can use the sample I did show you
for that.

Then you make that boundcolumn not visible and get that hidden column back
from the session when you need it, that is very simple in my opinion.

Cor
Nov 20 '05 #7
Hi Frank,

I added it on the wrong place, and this gives me the change to correct some
double writting.

When you look at my sample, than I think you can make, from the column you
want to make non visable, a datatable from one column.

Then you make that boundcolumn not visible and get that hidden column back
from the session when you need it, that is very simple in my opinion.

I hope this helps better?

Cor
Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Billy Jacobs | last post by:
I am using a datagrid to display some data. I need to create 2 header rows for this grid with columns of varying spans. In html it would be the following. <Table> <tr> <td colspan=8>Official...
5
by: Prateek | last post by:
Hi, How can I change the width of a column in datagrid control? TIA Prateek
9
by: web1110 | last post by:
Hi y'all, I have resized the columns in a DataGrid and I want to set the width of the DataGrid to fit the columns. Just summing the column widths is too short due to the grid and gray row...
2
by: Josef Meile | last post by:
Hi, I'm using a ComboBox, some Textboxes, and a DataGrid to represent a many-to-many relationship between Person and Course. Each time that I change the value in the ComboBox (which for now is...
5
by: John M | last post by:
Hello, In Visual Studio .NET 2003, How can I change the columns' width (at design or runtime) of datagrid ? Thanks :)
2
by: CSL | last post by:
I am using the DataGrid in a Windows Application, how can I adjust the widths of each column individually.
4
by: Steve | last post by:
I am fairly new to VB.NET, and I am rewriting an application I wrote a while back, also in VB.NET. I aplied some new things I learned. Anyway, here is my problem....... I have a custom DataGrid...
6
by: Agnes | last post by:
I understand it is impossible, but still curious to know "Can I freeze several column in the datagrid, the user can only scroll the first 3 columns (not verical), for the rest of the coulumn, it is...
10
by: amiga500 | last post by:
Hello, I have one basic simple question. When I have multiple records in the datagrid as follows: Code Product 1 Product 2 Product 3 11111 A B C...
2
by: =?Utf-8?B?Y3JlYXZlczA2MjI=?= | last post by:
I have a nested datagrid in a xaml file, the parent datagrid loads the vendor information and the details loads the documents for that vendor in a datagrid. Everything is working fine until I click...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.