• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 750
  • Last Modified:

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
0
introlux
Asked:
introlux
  • 10
  • 8
1 Solution
 
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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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
 
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 10
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now