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
introluxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David H.H.LeeCommented:
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.



0
introluxAuthor Commented:
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:            }

 
0
prairiedogCommented:
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.
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

introluxAuthor Commented:
text-overflow:ellipsis;

My CSS does not seem to like the above code?????
0
prairiedogCommented:
It is ok. Just try it.
0
introluxAuthor Commented:
text-overflow is not accepted in CSS
0
introluxAuthor Commented:
States text-overflow is not a know CSS name
0
prairiedogCommented:
Visual Studio does not recognize it does not mean the browser will not accept it. Did have have a chance to try it yet?
0
introluxAuthor Commented:
The ellipsis is not working
0
prairiedogCommented:
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
0
introluxAuthor Commented:
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
0
prairiedogCommented:
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.
0
introluxAuthor Commented:
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??
0
prairiedogCommented:
Yes. You can add another style just for the heading like this:
.tbl header
{
   white-space:normal;
}
and set GridView's HeaderStyle's CssClass = "header". It will wrap the text in the header but not in the rows.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
introluxAuthor Commented:
I have done this and still it does not do what I want it to do...............
0
prairiedogCommented:
>>>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.
0
introluxAuthor Commented:
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
0
prairiedogCommented:
It should wrap the text. Could you post your code?
0
introluxAuthor Commented:
Forgot to post back, but this actually worked.

Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.