Discovering row height of autosized GridView row in ASP.NET - 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.

Related

How to span the single column in an ASP.NET Gridview HORIZONTALLY

i have a Gridview with a single column which is a template field with an image and a label.
By default, the gridview expands vertically according to the items in the datasource.
But in my case most of the screen space is left unused and the page becomes extremely long.
So it'd be great if the one and only template field automatically becomes a new column (starts again from the top next to it's initial position after a fixed height) or SPANS HORIZONTALLY, not vertically...
i've done some searching and still can't find a solution for this..
any help would be great..!
i took 2 screenshots for a better explanation but the site won't allow me to post images yet :/
I think you are looking for the DataList control. Namely, the RepeatColumns property.

Sizing a Flex DataGrid to fit the data, then scrolling

I have a UI that is a master/details UI design pattern. There is a DataGrid that holds 1-n records in the top part section of a VDividedBox, then a details pane in the bottom part that shows details of the record selected in the DataGrid, responding to the selection.
The DataGrid usually only contains a small number of items, and so I'd like in most cases for the DataGrid to size to the number of rows and for the details pane to be shown just below the table with no empty space or empty rows. I've got that working OK by setting rowCount="{tableData.length}", where tableData is the data provider. So far, so good.
However, occasionally the table contains a larger number of items, and in these cases I'd like the table to grow to fill the available space, then scroll when there are too many items to show, without the details pane scrolling off. That is, behave like the rowCount is not set to the dataprovider length, and the height set to 100%.
My problem is, determining when to make this switch. What is the best way to switch the behavior from the rowCount-based height, to the percentage based height? Or am I missing some trick that would make the rowCount-based height table scroll when it runs out of space?
Thanks,
Paddy
What if you set the rowCount via:
rowCount="{tableData.length > 30 ? 30 : tableData.length }"
where 30 is the max height you want to scale to?
That way if there are more than 30 (or some #) of rows it will scroll.

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.

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.

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