Solved

ASP.net : how to set column width in datagrid

Posted on 2011-02-11
5
720 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
tutorial for ebay api 3 35
SQL Help 27 45
VB.Net Tranfer data between to VB.Net apps 8 26
List<PaisEntity> - show some 1 24
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

803 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