locked
Word Wrapping or column width. RRS feed

  • Question

  • User341939224 posted

    I have several tables that pull info from a database and I cant seem to work out how to limit the width of the columns so that they fit to the page correctly. I have tried applying width and text attributes in the css, but they have not worked was just wondering if anyone had any suggestions.

    Wednesday, September 19, 2012 7:56 AM

Answers

  • User-821857111 posted

    WebGrid columns have a "style" parameter which takes a string to represent the CSS class to apply. For example, you could have the following styles:

    .thirtypx {width:30px;}
    .fortypx {width:40px;}

    You can apply them like this:

    @grid.GetHtml(
            tableStyle: "grid",
            headerStyle: "head",
            alternatingRowStyle: "alt",
            columns: grid.Columns(
                grid.Column("ProductId", style: "fortypx"), 
                grid.Column("ProductName", style: "thirtypx")
                )
            )



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 19, 2012 8:48 AM

All replies

  • User-821857111 posted

    WebGrid columns have a "style" parameter which takes a string to represent the CSS class to apply. For example, you could have the following styles:

    .thirtypx {width:30px;}
    .fortypx {width:40px;}

    You can apply them like this:

    @grid.GetHtml(
            tableStyle: "grid",
            headerStyle: "head",
            alternatingRowStyle: "alt",
            columns: grid.Columns(
                grid.Column("ProductId", style: "fortypx"), 
                grid.Column("ProductName", style: "thirtypx")
                )
            )



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 19, 2012 8:48 AM
  • User341939224 posted

    I am currently pulling the into html <table>, would you recommend that I change to WebGrid?

    Wednesday, September 19, 2012 8:53 AM
  • User-821857111 posted

    A WebGrid renders as an HTML table. It is pretty easy to work with for displaying data from a database. when I saw your question, I kind of assumed you might be using the WebGrid anyway.

    Wednesday, September 19, 2012 2:20 PM