Results 1 to 5 of 5

Thread: DataGrid- Columns Width

  1. #1

    Thread Starter
    Hyperactive Member buddu's Avatar
    Join Date
    Jul 2001
    Location
    India
    Posts
    446

    DataGrid- Columns Width

    hi
    Can anyone give me a lines of code to display the datagrid in specified column width. I mean the columns of datagrid shold be arriged by the developer.

    Thanks
    prasad

  2. #2
    Addicted Member
    Join Date
    Aug 2001
    Location
    Pennsylvania
    Posts
    133

    Width

    PHP Code:

    'First you have to give the datagrid a percentage to work form

    dg.Width = Unit.Percentage(300)


    '
    then in your code you can tell the datagrid what field you want to change the width of.

     
    dg.Columns(4).ItemStyle.Width Unit.Percentage(5
    The important thing to understand is: The original width can be greater than 100%. I have found no documentation to validate this, just what I have come up with on my own.

  3. #3

    Thread Starter
    Hyperactive Member buddu's Avatar
    Join Date
    Jul 2001
    Location
    India
    Posts
    446
    Hi Abashai

    What ever u hv given is correct for Writing the code in OnLoad of Event. But I need to write the code Where i have the line of code for DataGrid It must be something like
    Code:
     <asp:datagrid id="DataGrid1" runat="server" backcolor="#EEEEEE" top="20px" Height="60px" Width="487" PageSize="20" AutoGenerateColumns="False" showHeader="false">
    <Columns>
    <asp:BoundColumn DataField="projCode" ReadOnly="True">               </asp:BoundColumn>
    ...
    ...
    [color=red]
    < Column1... Fixedwith="100" -- Someting like this
    ( I am just imaging the code like this) [/color=red]
    ...
    
    </asp:Grid>
    prasad

  4. #4
    Addicted Member
    Join Date
    Aug 2001
    Location
    Pennsylvania
    Posts
    133

    Reply

    I see what you are trying to do. I think you code has to post back to the server, so the page would have to load again.

    Each time the form loads you have to recreate the column.

    You might have code similar to this
    PHP Code:
    if not me.ispostback

            Dim Company 
    As New BoundColumn()
            
    Company.DataField "cCompanyName"
            
    Company.HeaderText "Company Name"
            
    Company.SortExpression "CompanyName"
            
    dgCustomers.Columns.Add(Company)
            
    dg.Columns(4).ItemStyle.Width Unit.Percentage(5

    end 
    if 

    If you are creating the datagrid at runtime then I would use something similar to the code above.

  5. #5

    Thread Starter
    Hyperactive Member buddu's Avatar
    Join Date
    Jul 2001
    Location
    India
    Posts
    446
    I found the Solution..

    We Need to add the Line of COde like
    <ItemTemplate Width="120">

    Thanks for tryails
    prasad

Posting Permissions

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



Click Here to Expand Forum to Full Width