PC Review


Reply
Thread Tools Rate Thread

datagrid width

 
 
Frank
Guest
Posts: n/a
 
      21st May 2004
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


 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      21st May 2004
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
///


 
Reply With Quote
 
=?Utf-8?B?UnVsaW4gSG9uZw==?=
Guest
Posts: n/a
 
      21st May 2004
It works that setting BoundColumn's Visible property to "False" .
 
Reply With Quote
 
=?Utf-8?B?cnVsaW5Ib25n?=
Guest
Posts: n/a
 
      21st May 2004
Set BoundColumn's Visible property to false.
 
Reply With Quote
 
Frank
Guest
Posts: n/a
 
      21st May 2004
then the data is not sent back in the postback.

"rulinHong" <(E-Mail Removed)> wrote in message
news:32508786-BFFF-46C9-BF34-(E-Mail Removed)...
> Set BoundColumn's Visible property to false.



 
Reply With Quote
 
Frank
Guest
Posts: n/a
 
      22nd May 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Frank,


[clipped]


 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      22nd May 2004
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


 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      22nd May 2004
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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGrid Width web1110 Microsoft C# .NET 9 25th Mar 2005 05:23 PM
DataGrid Width Debbie Carter Microsoft VB .NET 2 29th Sep 2004 08:01 AM
Datagrid col width Prateek Microsoft Dot NET 5 9th Jan 2004 01:05 AM
Datagrid col width Prateek Microsoft Dot NET 0 8th Jan 2004 05:27 PM
DataGrid width Prateek Microsoft ASP .NET 0 8th Jan 2004 04:30 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:43 AM.