Link to home
Start Free TrialLog in
Avatar of introlux
introluxFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Gridview Cell Display Help c#

Hi,

I would like to ensure that the data is wrapped for two rows of space. I am setting the width for each cell like this:

cell.Style["Width"] = "100px";

For each row I have this code:

    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        foreach (TableCell cell in e.Row.Cells)
        {
            cell.Wrap = false;
            cell.Style["overflow"] = "hidden";
            cell.Style["text-overflow"] = "ellipsis";
        }
    }

I would onlly like it to display two rows height, with a width of 100px. If it goes over this to display the ellipsis.

Any idea??

Regards,

introlux
Avatar of David H.H.Lee
David H.H.Lee
Flag of Malaysia image

Hi introlux,
Have you try with this?
cell.Style["Width"] = Unit.Pixel(100);

However, you can check the width of each entered before set the preferred width to 100px.



Avatar of introlux

ASKER

Compiler Error Message: CS0029: Cannot implicitly convert type 'System.Web.UI.WebControls.Unit' to 'string'

Source Error:

 

Line 243:                cell.Style["overflow"] = "hidden";
Line 244:                cell.Style["text-overflow"] = "ellipsis";
Line 245:                cell.Style["Width"] = Unit.Pixel(100);
Line 246:            }

 
Be aware, though, "text-overflow" only works in IE.
Create a style in your CSS like this:
.
.tbl
{
table-layout:fixed;
}
.tbl td
{
text-overflow:ellipsis;
overflow:hidden;
white-space:nowrap;
width:100px;
}
Then set GridView's CssClass = "tbl", and you are done. You don't need those code-behind code.
text-overflow:ellipsis;

My CSS does not seem to like the above code?????
It is ok. Just try it.
text-overflow is not accepted in CSS
States text-overflow is not a know CSS name
Visual Studio does not recognize it does not mean the browser will not accept it. Did have have a chance to try it yet?
The ellipsis is not working
1. It only works in IE.
2. Make sure you link the CSS file in your page.
3. The GridView has to have a fixed width.

2008-11-07-115649.jpg
Yes, but look at the headings. They have been cut off. I would like the headings to be displaye din full and the data which you have highlighted in yellow to have ellipsis.

Regards,

introlux
That is because the header text in my example is longer than 100px. If your header text is the same, then adjust the width in the style to accommodate it.
So is there no way to put a word onto two lines? example:

Word: Have a great Day

This will normally be displayed like this in teh header:

Have a great Day

I would like it displayed like this:
Have a
Great Day

Any idea how this can be achieved??
ASKER CERTIFIED SOLUTION
Avatar of prairiedog
prairiedog
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I have done this and still it does not do what I want it to do...............
>>>I have done this and still it does not do what I want it to do...............
It does not help me, man. You will need to be more specific about your problem.
I would like it displayed like this:
Have a
Great Day            <--------------------Does not display header like this even though I have done what you have said by using the CSS
It should wrap the text. Could you post your code?
Forgot to post back, but this actually worked.

Thanks