By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,949 Members | 1,554 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,949 IT Pros & Developers. It's quick & easy.

Datagrid table cells and rows -- Changing width

P: n/a
Hi,

I have a datagrid that contains 3 colums. This is rendered to the page fine,
except that I would like to be able to control the width of each table cell
of the datagrid
I have the following code in the "ItemDataBound" -- which I belive should
allow me to alter the width of the cells, however it does not work.

Dim unitWidth As Unit
unitWidth.Percentage(10)
e.Item.Cells(0).Width = unitWidth
unitWidth.Percentage(80)
e.Item.Cells(1).Width = unitWidth
unitWidth.Percentage(10)
e.Item.Cells(2).Width = unitWidth
Response.Write("dgSurveyDates_ItemDataBound<br>")
After this I tried placing the width attribute into the HTML of the
datagrid, however that gave a runtime error.

can anybody explain how to do this please.. I would also like to add client
side events such as "onmouseover" to the <tr> tag of each row, but I can't
seem to be able to do this either..

any help or advice would be appreciated.

thanks in advance.

martin.
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Martin,

You don't have full control over column width. The browser considers your
width instructions as recommendations. You can trick it a bit though. One of
the tricks I am using is setting the width to 1px for a column that I want
to be as narrow as possible. Then the browser will set the width of this
column to the width of the longest word. You can use non-breaking spaces to
join several words into one.

Setting cell width for every row separately, as in your example, doesn't
make much sence since all cells in one column have to have the same width.

The following C# code adds onmouseover event to the row:
e.Item.Attributes["onmouseover"] = "return myEventHandler(this)";

Eliyahu

"martin" <St**************@yahoo.com> wrote in message
news:uT**************@TK2MSFTNGP10.phx.gbl...
Hi,

I have a datagrid that contains 3 colums. This is rendered to the page fine, except that I would like to be able to control the width of each table cell of the datagrid
I have the following code in the "ItemDataBound" -- which I belive should
allow me to alter the width of the cells, however it does not work.

Dim unitWidth As Unit
unitWidth.Percentage(10)
e.Item.Cells(0).Width = unitWidth
unitWidth.Percentage(80)
e.Item.Cells(1).Width = unitWidth
unitWidth.Percentage(10)
e.Item.Cells(2).Width = unitWidth
Response.Write("dgSurveyDates_ItemDataBound<br>")
After this I tried placing the width attribute into the HTML of the
datagrid, however that gave a runtime error.

can anybody explain how to do this please.. I would also like to add client side events such as "onmouseover" to the <tr> tag of each row, but I can't
seem to be able to do this either..

any help or advice would be appreciated.

thanks in advance.

martin.

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.