Solved

ASP.net : how to set column width in datagrid

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now