gridview: table-layout: fixed but with different width for columns - asp.net

I hava a gridView with different width of columns (15%,17% ect...).
Some cell contain a very long text- in order to make all text seen and not truncated I used table-layout= fixed in the property "Style" of the gridview.
The problem is- the fixed property makes all columns' width to be equal and not what I defined.
How can I fix this?

<asp:GridView id="grd" style="width:100%"></asp:GridView>

Related

Set width of GridView DateItem based on content

I am binding all the columns of the dataSource using AutoGenerateColumns="true" property. Width of the header cell is default width of GridView column.
The purpose is to create a decent table layout, with minimal work on markup. Thus trying to skip binding each column explicitly.
Is there a way to achieve this in GridView i.e. to set width of column based on content of the cell. i.e.
<tr><th>DummyHeaderContainingMoreLength</tr></th>
<tr><td>cellContent</tr></td>
Can I obtain width of the cell as lengthof(cellContent), let the header float or truncate.
Set width="100%". This will do.

aspnet table - specify TableCell width?

I've a asp.net table and I'm trying to format my columns to be all equal widths, or say 4 columns of 20%, 30%, 20% and 30%. However the following code is not working:
<asp:TableCell Width="30%">
The 'height' attribute works but this isn't the one I'm after. Any help much appreciated. Thanks
It's not working because the Width property is expecting a value of a Unit type, which defaults to Pixels.. I couldn't find an example that shows how to create an instance of Unit with a Type of Percentage
Which leaves me to suggest how you could do it with CSS..
Give the TableCell a CssClass, and set the Width in a stylesheet
<asp:TableCell CssClass="tableCellWidth30">
.tableCellWidth30 { width:30%; }
Use the Style property and set the Width inline
<asp:TableCell Style="width:30%;">
If you want to add a css style via code, do it like this:
txtmark.Style("font-weight") = "normal"
I couldn't find this answer anywhere, so that is why i posted it here.

Gridview height issue

This is a simple one but it is defeating me.
Ok, I have a gridview, lovely stuff. I have attempted to set the height of the headers so that the height is maintained regaardless of the content of the gridview.
However, if a data row requires a bit more height itself (to include the data), the height of the heading also increases.
How do I go about ensuring the height of the header is maintained but not at the expense of the data rows themselves?
GridView provides interesting styling features using asp.net tags in grid view, If you want to style height of a header, you can do something like this:
<asp:GridView id='grd' runat='server'>
<HeaderStyle Height="30px"/>
&lt/asp:GridView>
or in headerStyle you can also use CssClass where you can assign the css style class specified.
Hope this helps
I found the reason behind my mysterious expanding rows!!
Bascially, I had set the height of my gridview. When the gridview was full with data and resulted in paging, the heading remained as it should. However, the rows expanded when this gridview was below it's quota of data - essentially .net was being clever and trying to fill the space I had created by setting the height by expanding what it could.
All I did was to remove the height of my gridview and it worked a treat.
Thanks for all the pointers though : )
You can use styles to set almost all presentation attributes. Try out using a css or add style attributes.

Discovering row height of autosized GridView row in ASP.NET

I have a number of GridView controls that I need to position side-by-side on a page. For example a GridView containing a list of items in a shopping basket, and a number of GridViews to the side showing pricing from a number of suppliers.
The columns are fixed width in the first GridView - meaning that the row height is variable depending on the amount of text.
So, the question is this - is there any way to discover the individual row heights of the first data-bound GridView such that I can alter the other GridViews to correctly align?
The Row.Height property of the grid after databinding is empty as the height has not been explicity set.
thanks!
I don't know of any way to do this in .Net, you can use javascript, maybe set a .Net hidden field on load if you need it in code behind :
var h = document.getElementsByTagName('td')[0].offsetHeight;
Keep in mind this height will also include any cell padding or spacing you have set. Also, this assumes you're not explicitly setting the height in CSS which based on your question I assume you are not.

How to set columns widths in a GridView control to the widest necessary width

I have a gridview control that can get loaded with multiple pages worth of data. When I switch pages, the columns widths will change to accommodate the largest value in the column for that page.
If possible, I would like to set the widths of each column to the widest necessary width for the entire dataset.
You can set the ItemStyle-Width property on each TemplateField, BoundField, etc. in your gridview to whatever you want. That should hold across paging. You will want to either not set the gridview width, or be sure you don't use a percentage if you do.
If you want to figure this out dynamically, you will have to examine your data first, before binding your grid, figure out the width that you want, then bind your gird and dynamically set the ItemStyle-Width in the RowDataBound event of the gridview.
Tring things, in the edit colum menu of your grid you should try the auto size mode, I configure my to cell and it work pretty well for my needs..
This is available when you are not autogenerating the columns.
Try it.

Resources