problem sizing columns in datagrid

Discussion in 'ASP .Net Datagrid Control' started by Mad Scientist Jr, Aug 13, 2004.

  1. 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, Aug 13, 2004
    #1
    1. Advertising

  2. Mad Scientist Jr

    anon Guest

    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 http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    anon, Aug 18, 2004
    #2
    1. Advertising

  3. actually that's not a bad idea... thanks for responding
     
    Mad Scientist Jr, Aug 20, 2004
    #3
  4. Mad Scientist Jr

    Mike Hutton Guest

    anon <> wrote in message news:<#>...
    > 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, Aug 24, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    378
  2. MISS CHIEVOUS
    Replies:
    51
    Views:
    2,084
    MISS CHIEVOUS
    Apr 19, 2009
  3. rob thomson
    Replies:
    0
    Views:
    264
    rob thomson
    Sep 4, 2003
  4. Keefe Goldfisher via .NET 247

    Sizing text entry boxes on in-place editing of datagrid row with dynamically created columns

    Keefe Goldfisher via .NET 247, Mar 7, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    182
    Keefe Goldfisher via .NET 247
    Mar 7, 2005
  5. ton
    Replies:
    2
    Views:
    207
    Alvin Bruney [MVP]
    Feb 11, 2004
Loading...

Share This Page