Set Width in DataGrid columns

Discussion in 'ASP .Net' started by Alberto, Feb 4, 2004.

  1. Alberto

    Alberto Guest

    I have a dataGrid control in an ascx module. The code is this:

    gridUsers.DataSource = users.GetUsers();
    gridUsers.DataBind();

    As you can see, the GetUsers() method returns a DataSet object.

    What I want is modify the widht of the columns. I have to do it in code
    (because it's linked in runtime) but I don't know how to do it.

    Thank you.
    Alberto, Feb 4, 2004
    #1
    1. Advertising

  2. Alberto

    Janaka Guest

    The width of the columns is set in the ascx file and hasn't got anything to
    do with DataBinding. You set the width by using the syntax
    ItemStyle-Width="width" and HeaderStyle-Width="width" in your BoundColumn
    or TemplateColumn

    "Alberto" <> wrote in message
    news:...
    > I have a dataGrid control in an ascx module. The code is this:
    >
    > gridUsers.DataSource = users.GetUsers();
    > gridUsers.DataBind();
    >
    > As you can see, the GetUsers() method returns a DataSet object.
    >
    > What I want is modify the widht of the columns. I have to do it in code
    > (because it's linked in runtime) but I don't know how to do it.
    >
    > Thank you.
    >
    >
    Janaka, Feb 4, 2004
    #2
    1. Advertising

  3. Alberto

    Alberto Guest

    I tried with this:
    gridUsers.Columns[0].ItemStyle.Width = 1000;
    and with this:
    gridUsers.Columns[0].Heather.Width = 1000;

    But none of them works.

    "Janaka" <> escribió en el mensaje
    news:...
    > The width of the columns is set in the ascx file and hasn't got anything

    to
    > do with DataBinding. You set the width by using the syntax
    > ItemStyle-Width="width" and HeaderStyle-Width="width" in your BoundColumn
    > or TemplateColumn
    >
    > "Alberto" <> wrote in message
    > news:...
    > > I have a dataGrid control in an ascx module. The code is this:
    > >
    > > gridUsers.DataSource = users.GetUsers();
    > > gridUsers.DataBind();
    > >
    > > As you can see, the GetUsers() method returns a DataSet object.
    > >
    > > What I want is modify the widht of the columns. I have to do it in code
    > > (because it's linked in runtime) but I don't know how to do it.
    > >
    > > Thank you.
    > >
    > >

    >
    >
    Alberto, Feb 4, 2004
    #3
  4. Alberto

    Janaka Guest

    Try doing it in the html portion of the ascx file
    i.e.

    <BoundColumn id="Heather" DataField="foo" ItemStyle-Width="1000" />

    "Alberto" <> wrote in message
    news:...
    > I tried with this:
    > gridUsers.Columns[0].ItemStyle.Width = 1000;
    > and with this:
    > gridUsers.Columns[0].Heather.Width = 1000;
    >
    > But none of them works.
    >
    > "Janaka" <> escribió en el mensaje
    > news:...
    > > The width of the columns is set in the ascx file and hasn't got anything

    > to
    > > do with DataBinding. You set the width by using the syntax
    > > ItemStyle-Width="width" and HeaderStyle-Width="width" in your

    BoundColumn
    > > or TemplateColumn
    > >
    > > "Alberto" <> wrote in message
    > > news:...
    > > > I have a dataGrid control in an ascx module. The code is this:
    > > >
    > > > gridUsers.DataSource = users.GetUsers();
    > > > gridUsers.DataBind();
    > > >
    > > > As you can see, the GetUsers() method returns a DataSet object.
    > > >
    > > > What I want is modify the widht of the columns. I have to do it in

    code
    > > > (because it's linked in runtime) but I don't know how to do it.
    > > >
    > > > Thank you.
    > > >
    > > >

    > >
    > >

    >
    >
    Janaka, Feb 4, 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. Vincent
    Replies:
    1
    Views:
    353
    Vincent
    Aug 17, 2005
  2. Vincent
    Replies:
    1
    Views:
    444
    Lucas Tam
    Aug 17, 2005
  3. AndrewF
    Replies:
    1
    Views:
    741
    Bruce Barker
    Oct 10, 2005
  4. kris
    Replies:
    11
    Views:
    860
  5. ssk
    Replies:
    5
    Views:
    5,460
    Jukka K. Korpela
    Oct 30, 2006
Loading...

Share This Page