Avatar of Lagi
Lagi
 asked on

Datagrid column width manipulation

I have a datagrid which is connected to a dataview which is connected to a dataset.
I want to know how can I set EACH column width differently, something like : datagrid.column[0].width = 100, datagrid.column[1].width = 130, etc.
C#

Avatar of undefined
Last Comment
mpest

8/22/2022 - Mon
mpest

Do it from your aspx page, not the aspx.cs page

<asp:TemplateColumn HeaderText="Cost">
     <ItemTemplate>
          <asp:Label id="lblCost" runat="server" text='<%# Convert.ToString(DataBinder.Eval(Container.DataItem,"Cost")) %>' Width="75" />
     </ItemTemplate>
<asp:TemplateColumn>

Will set it to 75
ASKER CERTIFIED SOLUTION
Éric Moreau

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Lagi

ASKER
The grid in within windows application not browser.
mpest

did you try
DG.Columns[0].HeaderStyle.Width = 100
Your help has saved me hundreds of hours of internet surfing.
fblack61