Solved

ASP.net : how to set column width in datagrid

Posted on 2011-02-11
5
722 Views
Last Modified: 2012-05-11
Hi,
  I'm very new to ASP.net. I have a datagrid that allows viewing and update of records and i would like to set the column width accordingly.The records should be displayed on a single line with no wrapping.  I've tried ItemStyle-Width ..etc with no luck. Please help me with the following code snippet. Thanks in advance.

 <asp:datagrid id="DataGrid1" runat="server" Width="600px" Font-Names="Arial" AutoGenerateColumns="False" CellSpacing="1" GridLines="None" CellPadding="3" BackColor="White" OnPageIndexChanged="DataGrid_Page" PageSize="20" OnCancelCommand="DataGrid_Cancel" OnUpdateCommand="DataGrid_Update" OnEditCommand="DataGrid_Edit" Font-Size="XX-Small" ForeColor="Black">
                <FooterStyle wrap="False" backcolor="#C6C3C6"></FooterStyle>
                <HeaderStyle font-bold="True" wrap="False" horizontalalign="Center" forecolor="White" backcolor="#0000C0"></HeaderStyle>
                <PagerStyle font-size="XX-Small" horizontalalign="Right" backcolor="#C6C3C6" wrap="False" mode="NumericPages"></PagerStyle>
                <SelectedItemStyle wrap="False"></SelectedItemStyle>
                <EditItemStyle wrap="False"></EditItemStyle>
                <AlternatingItemStyle wrap="False"></AlternatingItemStyle>
                <ItemStyle wrap="False" backcolor="#DEDFDE"></ItemStyle>
                <Columns>
                    <asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit">
                        <ItemStyle font-size="XX-Small" width="10%"></ItemStyle>
                    </asp:EditCommandColumn>
                    <asp:TemplateColumn HeaderText="SO #">
                        <ItemStyle horizontalalign="Center"></ItemStyle>
                        <ItemTemplate>
                            <%# Container.DataItem("STDOCO") %>
                        </ItemTemplate>
                        <FooterTemplate>
                            <asp:TextBox id="SOTxt" runat="server" horizontalalign="Center" Columns="4" />
                        </FooterTemplate>
                        <EditItemTemplate>
                            <asp:TextBox id="SO" runat="server" Text='<%# Container.DataItem("STDOCO") %>' horizontalalign="Center" Columns="4" readonly="true" ForeColor="Gray" />
                        </EditItemTemplate>
                    </asp:TemplateColumn>
            </Columns>
            </asp:datagrid>

0
Comment
Question by:DB-IT
5 Comments
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 250 total points
ID: 34868970
Try any of these entries to prevent word wrap. By default word wrap is turned on.

<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 109px; POSITION: absolute; TOP: 94px" runat="server">
    <SelectedItemStyle Wrap="False"></SelectedItemStyle>
    <EditItemStyle Wrap="False"></EditItemStyle>
    <AlternatingItemStyle Wrap="False"></AlternatingItemStyle>
    <ItemStyle Wrap="False"></ItemStyle>
    <HeaderStyle Wrap="False"></HeaderStyle>
    <FooterStyle Wrap="False"></FooterStyle>
    <PagerStyle Wrap="False"></PagerStyle>
</asp:DataGrid
0
 
LVL 9

Expert Comment

by:s_chilkury
ID: 34868983
0
 
LVL 3

Assisted Solution

by:amittripathi8
amittripathi8 earned 250 total points
ID: 34869828
it's better to ste all the things in % beacuse it will work according to resolution you have.
0
 
LVL 19

Expert Comment

by:Amandeep Singh Bhullar
ID: 35906815
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question