datagrid width

  • Thread starter Thread starter Frank
  • Start date Start date
F

Frank

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
 
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
///
 
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 said:
Hi Frank,

[clipped]
 
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
 
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
 
Back
Top