Professional Web Applications Themes

Changing Width of Datagrid (AutoGenerateColumn=true) - ASP.NET Data Grid Control

Hi, hope some1 can help me trying this about a week. I read the data for my Datagrid into a dataset, convert a little bit and store the finalresult in another ds from an Access-DB and bind the data ds.Tables.Add("Vendor") With ds.Tables("Vendor").Columns ..Add("Verkäufer") ..Add("Name") ..Add("Umsatz") ..Add("Kunden") ..Add("øKauf") ..Add("Positionen/Kunde") ..Add("Umsatz/Bereich") End With query = "SELECT ....." da.SelectCommand = New OleDb.OleDbCommand(query, cn) da.Fill(ds, "Salesperson") .... conversion and "Salesperson"->"Vendor" .... DataGrid1.DataSource = ds.Tables("Vendor").DefaultView DataGrid1.DataBind() And after the DataBind my datagrid1.colums.count is always 0. this is because of the AutoGenerateColumn=true, i've read. But i can't figure out how i should change the width of ...

  1. #1

    Default Changing Width of Datagrid (AutoGenerateColumn=true)

    Hi, hope some1 can help me trying this about a week.

    I read the data for my Datagrid into a dataset, convert a little bit
    and store the finalresult in another ds from an Access-DB and bind the
    data

    ds.Tables.Add("Vendor")
    With ds.Tables("Vendor").Columns
    ..Add("Verkäufer")
    ..Add("Name")
    ..Add("Umsatz")
    ..Add("Kunden")
    ..Add("øKauf")
    ..Add("Positionen/Kunde")
    ..Add("Umsatz/Bereich")
    End With

    query = "SELECT ....."
    da.SelectCommand = New OleDb.OleDbCommand(query, cn)
    da.Fill(ds, "Salesperson")
    ....
    conversion and "Salesperson"->"Vendor"
    ....
    DataGrid1.DataSource = ds.Tables("Vendor").DefaultView
    DataGrid1.DataBind()

    And after the DataBind my datagrid1.colums.count is always 0. this is
    because of the AutoGenerateColumn=true, i've read.

    But i can't figure out how i should change the width of a column.
    DataGrid1.Columns(0).ItemStyle.Width = Unit.Pixel(100)
    does NOT work, because VB.NET says my Datagrid has 0 Columns.

    But if I look at my asp Page I can see the whole Datagrid.

    Hope some1 has an idear and perhaps even some code.
    Gh0st Guest

  2. #2

    Default Re: Changing Width of Datagrid (AutoGenerateColumn=true)

    Are you making the width altering call after you bind the data to the grid?
    mygrid.datasoucre = mydataset.Tables(0)
    mygrid.databind
    mygrid.Columns(0).ItemStyle.Width = Unit.Pixel(100)

    You might want to look at making the changes in the ItemCreated or
    ItemDatabound events.

    "Gh0st" <ghosthuntergmx.at> wrote in message
    news:25c9c5e0.0410110342.4acfbe6cposting.google.c om...
    > Hi, hope some1 can help me trying this about a week.
    >
    > I read the data for my Datagrid into a dataset, convert a little bit
    > and store the finalresult in another ds from an Access-DB and bind the
    > data
    >
    > ds.Tables.Add("Vendor")
    > With ds.Tables("Vendor").Columns
    > .Add("Verkäufer")
    > .Add("Name")
    > .Add("Umsatz")
    > .Add("Kunden")
    > .Add("øKauf")
    > .Add("Positionen/Kunde")
    > .Add("Umsatz/Bereich")
    > End With
    >
    > query = "SELECT ....."
    > da.SelectCommand = New OleDb.OleDbCommand(query, cn)
    > da.Fill(ds, "Salesperson")
    > ...
    > conversion and "Salesperson"->"Vendor"
    > ...
    > DataGrid1.DataSource = ds.Tables("Vendor").DefaultView
    > DataGrid1.DataBind()
    >
    > And after the DataBind my datagrid1.colums.count is always 0. this is
    > because of the AutoGenerateColumn=true, i've read.
    >
    > But i can't figure out how i should change the width of a column.
    > DataGrid1.Columns(0).ItemStyle.Width = Unit.Pixel(100)
    > does NOT work, because VB.NET says my Datagrid has 0 Columns.
    >
    > But if I look at my asp Page I can see the whole Datagrid.
    >
    > Hope some1 has an idear and perhaps even some code.

    Jared Guest

  3. #3

    Default Re: Changing Width of Datagrid (AutoGenerateColumn=true)

    yes i make the with after the databind

    I can't do it in the Itemcreated because i want to set the width of
    all Columns so the same size the largest Column had.
    Like (rough example):
    dim width as integer
    for i as interger=0 to datagrid1.columns.count
    if width < datagrid1.colums(i).width
    width=datagrid1.colums(i).width
    next

    for each column as datacolumn in datagrid1.columns
    column.width=width
    next

    Don't know if the code is exactly correkt but i think you'll know what
    i mean.

    the Itemcreated is fired everytime a new item is created, ok i can
    check there if it is a header and count... but then i still have the
    problem with accessing a column in the datagrid. (columns = 0)


    "Jared" <ask_me_for_itnospam.com> wrote in message news:<10mkvkqbnghn127corp.supernews.com>...
    > Are you making the width altering call after you bind the data to the grid?
    > mygrid.datasoucre = mydataset.Tables(0)
    > mygrid.databind
    > mygrid.Columns(0).ItemStyle.Width = Unit.Pixel(100)
    >
    > You might want to look at making the changes in the ItemCreated or
    > ItemDatabound events.
    >
    > "Gh0st" <ghosthuntergmx.at> wrote in message
    > news:25c9c5e0.0410110342.4acfbe6cposting.google.c om...
    > > Hi, hope some1 can help me trying this about a week.
    > >
    > > I read the data for my Datagrid into a dataset, convert a little bit
    > > and store the finalresult in another ds from an Access-DB and bind the
    > > data
    > >
    > > ds.Tables.Add("Vendor")
    > > With ds.Tables("Vendor").Columns
    > > .Add("Verkäufer")
    > > .Add("Name")
    > > .Add("Umsatz")
    > > .Add("Kunden")
    > > .Add("øKauf")
    > > .Add("Positionen/Kunde")
    > > .Add("Umsatz/Bereich")
    > > End With
    > >
    > > query = "SELECT ....."
    > > da.SelectCommand = New OleDb.OleDbCommand(query, cn)
    > > da.Fill(ds, "Salesperson")
    > > ...
    > > conversion and "Salesperson"->"Vendor"
    > > ...
    > > DataGrid1.DataSource = ds.Tables("Vendor").DefaultView
    > > DataGrid1.DataBind()
    > >
    > > And after the DataBind my datagrid1.colums.count is always 0. this is
    > > because of the AutoGenerateColumn=true, i've read.
    > >
    > > But i can't figure out how i should change the width of a column.
    > > DataGrid1.Columns(0).ItemStyle.Width = Unit.Pixel(100)
    > > does NOT work, because VB.NET says my Datagrid has 0 Columns.
    > >
    > > But if I look at my asp Page I can see the whole Datagrid.
    > >
    > > Hope some1 has an idear and perhaps even some code.
    Gh0st Guest

  4. #4

    Default Re: Changing Width of Datagrid (AutoGenerateColumn=true)

    Yeeehaaaw just made it

    query = "SELECT Country, ZIP FROM ZIP GROUP BY Country, ZIP"
    da.SelectCommand = New OleDb.OleDbCommand(query, cn)
    da.Fill(ds, "Country")

    Dim col As New BoundColumn
    col.HeaderText = "Stadt"
    col.DataField = "Country"
    DataGrid1.Columns.Add(col)

    DataGrid1.DataSource = ds

    DataGrid1.DataBind()
    DataGrid1.Columns(0).HeaderStyle.Width = Unit.Pixel(200)

    this is the way i can change the width like i want. But thx für help Jared



    "Jared" <ask_me_for_itnospam.com> wrote in message news:<10mkvkqbnghn127corp.supernews.com>...
    > Are you making the width altering call after you bind the data to the grid?
    > mygrid.datasoucre = mydataset.Tables(0)
    > mygrid.databind
    > mygrid.Columns(0).ItemStyle.Width = Unit.Pixel(100)
    >
    > You might want to look at making the changes in the ItemCreated or
    > ItemDatabound events.
    >
    > "Gh0st" <ghosthuntergmx.at> wrote in message
    > news:25c9c5e0.0410110342.4acfbe6cposting.google.c om...
    > > Hi, hope some1 can help me trying this about a week.
    > >
    > > I read the data for my Datagrid into a dataset, convert a little bit
    > > and store the finalresult in another ds from an Access-DB and bind the
    > > data
    > >
    > > ds.Tables.Add("Vendor")
    > > With ds.Tables("Vendor").Columns
    > > .Add("Verkäufer")
    > > .Add("Name")
    > > .Add("Umsatz")
    > > .Add("Kunden")
    > > .Add("øKauf")
    > > .Add("Positionen/Kunde")
    > > .Add("Umsatz/Bereich")
    > > End With
    > >
    > > query = "SELECT ....."
    > > da.SelectCommand = New OleDb.OleDbCommand(query, cn)
    > > da.Fill(ds, "Salesperson")
    > > ...
    > > conversion and "Salesperson"->"Vendor"
    > > ...
    > > DataGrid1.DataSource = ds.Tables("Vendor").DefaultView
    > > DataGrid1.DataBind()
    > >
    > > And after the DataBind my datagrid1.colums.count is always 0. this is
    > > because of the AutoGenerateColumn=true, i've read.
    > >
    > > But i can't figure out how i should change the width of a column.
    > > DataGrid1.Columns(0).ItemStyle.Width = Unit.Pixel(100)
    > > does NOT work, because VB.NET says my Datagrid has 0 Columns.
    > >
    > > But if I look at my asp Page I can see the whole Datagrid.
    > >
    > > Hope some1 has an idear and perhaps even some code.
    Gh0st Guest

Similar Threads

  1. Changing the width/height when using Hyperlink.ImageUrl
    By Nathan Sokalski in forum ASP.NET Building Controls
    Replies: 1
    Last Post: October 10th, 10:36 PM
  2. Dynamically changing Application height & width
    By Gajam in forum Macromedia Flex General Discussion
    Replies: 1
    Last Post: August 23rd, 04:05 PM
  3. Changing Width
    By Omer Iqbal in forum Web Design
    Replies: 1
    Last Post: February 8th, 02:36 PM
  4. Changing Text Sprite Width
    By Pavel in forum Macromedia Director Lingo
    Replies: 1
    Last Post: November 22nd, 07:19 AM
  5. changing the pop-up menu width
    By Benny Alexander in forum Macromedia Fireworks
    Replies: 0
    Last Post: September 18th, 11:08 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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