?
Solved

Adjust Width of DataGrid to fit the page

Posted on 2007-08-08
5
Medium Priority
?
367 Views
Last Modified: 2012-05-05
I have placed  a datagrid on asp.net page which is bound to a DataReader. I have 20 fields to be displayed on form. Currently it has 2 fields + 1 hyperlink only. What is the property which has to be given to adjust the width of the DataGrid on the webpage
Here is the current code

<asp:DataGrid id="DataGrid1" runat="server" AutoGenerateColumns="False" CellPadding="1" HeaderStyle-HorizontalAlign="Center"
                  HeaderStyle-BackColor="Red" HeaderStyle-ForeColor="White" HeaderStyle-Font-Bold="True" HeaderStyle-Font-Name="Verdana"
                  AlternatingItemStyle-BackColor="#dddddd" ItemStyle-Font-Name="Verdana" BackColor="White" BorderWidth="1px"
                  BorderStyle="None" BorderColor="#CC9966">
                  <FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
                  <SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66"></SelectedItemStyle>
                  <ItemStyle Font-Names="Verdana" ForeColor="#330099" BackColor="White"></ItemStyle>
                  <HeaderStyle Font-Names="Verdana" Font-Bold="True" HorizontalAlign="Center" ForeColor="#FFFFCC"
                        BackColor="#990000"></HeaderStyle>
                  <Columns>
                        <asp:HyperLinkColumn Text="View FAQ" DataNavigateUrlField="project_id" DataNavigateUrlFormatString="http://aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID={0}"
                              HeaderText="View FAQ">
                              <ItemStyle HorizontalAlign="Center" Width="10%"></ItemStyle>
                        </asp:HyperLinkColumn>
                        <asp:BoundColumn DataField="project_id" HeaderText="Project ID">
                              <ItemStyle Wrap="False"></ItemStyle>
                        </asp:BoundColumn>
                        <asp:BoundColumn DataField="project_name" HeaderText="Project Name"></asp:BoundColumn>
                  </Columns>
                  <PagerStyle HorizontalAlign="Center" ForeColor="#330099" BackColor="#FFFFCC"></PagerStyle>
            </asp:DataGrid>
0
Comment
Question by:dotnet0824
  • 2
  • 2
5 Comments
 
LVL 37

Expert Comment

by:samtran0331
ID: 19658857
you can set the width property...
<asp:DataGrid ... Width="100%"
0
 
LVL 8

Expert Comment

by:sabeesh
ID: 19658911
write a css class for word wrap and break the word which is longer and give persentage wise division of all of the column and sum of each column with persentage should be 100%

STYLE="word-wrap: break-word">word
0
 

Author Comment

by:dotnet0824
ID: 19660220
can that CSS be shown
0
 
LVL 8

Accepted Solution

by:
sabeesh earned 1000 total points
ID: 19662203
Css

.word
{
      word-break:break-all;
}


aspx file


 <asp:GridView id="gridResourceItems" .......................



<asp:TemplateField HeaderText="Res">
                                    <EditItemTemplate>
                                        <asp:TextBox ID="txtRIL" TextMode="multiLine" Wrap="true" runat="server" Text='<%# Bind("ResourceLanguageDesc") %>' Width="100%"></asp:TextBox>
                                    </EditItemTemplate>
                                    <ItemStyle CssClass="word" HorizontalAlign="Left" VerticalAlign="Top" Width="22%" />
<FooterStyle Width="22%" VerticalAlign="Top" />
                                    <HeaderStyle Width="22%" HorizontalAlign="Center" />
                                    <ItemTemplate>
                                        <asp:Label ID="Label3" CssClass="word" runat="server"  Text='<%# Bind("Res") %>'></asp:Label>
                                    </ItemTemplate>
                                   
                                </asp:TemplateField>
0
 

Author Comment

by:dotnet0824
ID: 19666213
Thanks a lot
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Integration Management Part 2
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

850 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