problem sizing columns in datagrid

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default problem sizing columns in datagrid

    I have a datagrid that has a column that I would like to be the widest
    (say 60%) - however another column is populated with some data that is
    sometimes a rather long string, and it expands to take up most of the
    table width. I tried to force the column sizes to force the longer
    column to wrap but it isn't working. Any help appreciated, my code is
    below:

    DataGrid1.DataSource = DataTable1
    DataGrid1.DataBind()
    DataGrid1.Columns(0).ItemStyle.Width = Unit.Percentage(10)
    DataGrid1.Columns(1).ItemStyle.Width = Unit.Percentage(60)
    ' this column is getting squashed
    DataGrid1.Columns(2).ItemStyle.Width = Unit.Percentage(10)
    ' this column still ends up taking 70% or so
    DataGrid1.Columns(3).ItemStyle.Width = Unit.Percentage(10)
    Mad Scientist Jr Guest

  2. Similar Questions and Discussions

    1. Sizing text entry boxes on in-place editing of datagrid row with dynamically created columns
      Built a datagrid with dynamically created bound columns, andadded editing in-place, deletions and add-new features that workfine. One minor detail...
    2. Sizing the dataGrid
      I have a dataGrid on a form, In design mode it behaves as I would expect when resizing the form. However when I populate it when running, it no...
    3. Problem Hiding Columns when Populating a Datagrid with a DataView of A DataTable From Dataset returned via an Asynchronous Web-Service
      Hi I have a webservice that retrieves data from a database, this is then returned to the calling client application built in windows forms within...
    4. Autogenerated Datagrid columns rebinding problem on postback
      Just to give a brief background what I'm trying to do, is I have a DataGrid with 2 static columns, and the rest are autogenerated (which have...
    5. Columns and Inherited Datagrid...Active Schema does not support columns
      I have a class which has inherited from datagrid, to provide some custom functionality, row select, mouse overs etc All is working fine apart from...
  3. #2

    Default Re: problem sizing columns in datagrid


    One solution is to check the length of this particular column that is
    causing wider columns in itemdatabound....

    string d = Convert.ToString(DataBinder.Eval(e.Item.DataItem,. ...));
    if (d.Length > 50)
    {
    Label lb = (Label) e.Item.FindControl("lb");
    lb.Text = d.Substring(0, 45) + "...";

    }

    Hope that helps,
    Ben

    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    anon Guest

  4. #3

    Default Re: problem sizing columns in datagrid

    actually that's not a bad idea... thanks for responding
    Mad Scientist Jr Guest

  5. #4

    Default Re: problem sizing columns in datagrid

    anon <anonymous@devdex.com> wrote in message news:<#rYodEMhEHA.2916@TK2MSFTNGP12.phx.gbl>...
    > One solution is to check the length of this particular column that is
    > causing wider columns in itemdatabound....
    >
    > string d = Convert.ToString(DataBinder.Eval(e.Item.DataItem,. ...));
    > if (d.Length > 50)
    > {
    > Label lb = (Label) e.Item.FindControl("lb");
    > lb.Text = d.Substring(0, 45) + "...";
    >
    > }
    >
    > Hope that helps,
    > Ben
    I have a related problem, but one which I can't really use substrings
    on.

    I have a column which has generated HTML tags in it. The tag is a link
    to a javascript function which needs to be called with the key value
    of the row, and also has a JPG embedded in it. I want to be able to
    use this as my grid needs to be dynamic - I don't always want to
    display this column.

    As you can guess, the DataGrid is resizing my grid so that the column
    takes up space commensurate with the size of the text which generates
    the link, rather than the image it displays.

    Is there any way I can completely override the column width so it
    doesn't "correct" it in this way?

    Mike.
    Mike Hutton Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139