C# .NET - Grid View - Asked By April June on 16-Nov-11 12:25 AM

Hi All,

I have a grid view in which i am displaying data from database but there are column in which data is too large it  is shrinking in grid column as shown below.
Plz help i want to show it in one line only.






 
Chintan Vaghela replied to April June on 16-Nov-11 12:27 AM
Hello,

Increase GridView Width Size in px

Also Increase Template Width Size in px
Reena Jain replied to April June on 16-Nov-11 12:30 AM
hi,

try this line at the end of the grid data mapping

DataGridView1.AutoResizeColumns();

or check this link
http://www.codeguru.com/csharp/.net/net_data/datagrid/article.php/c9603
Jitendra Faye replied to April June on 16-Nov-11 12:31 AM
Increase the width of ItemTemplate in GridView like this-

set itemStyle-Width and HeaderStyle-Width in templatefiled


<asp:TemplateField HeaderText="User ID" HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="100px"
HeaderStyle-Width="100px" SortExpression="Updateddate">
<ItemTemplate>
<asp:Label ID="lblDateTime" runat="server" Text='<%#Eval("UpdateUser") %>' />
</ItemTemplate>
</asp:TemplateField>

Try this and let me know.
Anoop S replied to April June on 16-Nov-11 12:48 AM
Limit the gridview data and show that in tooltop

code

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
          ViewState["OrigData"] = e.Row.Cells[0].Text;
          if (e.Row.Cells[0].Text.Length >= 20) //Just change the value of 20 based on your requirements
          {
            e.Row.Cells[0].Text = e.Row.Cells[0].Text.Substring(0, 20) + "...";
            e.Row.Cells[0].ToolTip = ViewState["OrigData"].ToString();
          }

       }

aneesa replied to April June on 16-Nov-11 01:05 AM
Here Please check the 'Book Description Column' 
Inventory Valuation - Hardware Books
ID Title Book Description Price Qty Amount
HW111 How Computers Work
How Computers Work, 7th Edition, has been one of the bestselling computer books for the last 10 years. This four-color visual tutorial is a must-have for any computer user, from novice to expert. The rich graphics and intricate details about the inner workings of computers have been admired for years by consumers, instructors, professionals, and readers of all ages. A fresh cover and interior provide the reader with superior usability and it is the most aesthetically-pleasing edition yet!
$29.99 8 239.92
HW222 Upgrading and Repairing PCs
Push your PC's performance to the limit. Know the differences between: Pentium II, Pentium MMX, Pentium Pro, and earlier CPU chips and choose the best chip for your needs; understand compatibility and feature sets of processor upgrade sockets, motherboards, and chipsets; use Universal Serial Bus ports and devices to simplify peripheral installation, configuration, and improve performance; squeeze the most performance, life, and reliability out of your hard drives; prevent memory headaches: pick the right speed and type of SIMMs and DIMMs, run more programs at once, and work with bigger files; and integrate hot new hardware including 3D graphics accelerators, fast SDRAM memory, Zoomed Video and CardBus PC Cards for your notebook, and NLX motherboards with support for Single Edge Contact processors and Accelerated Graphics Ports.
$59.99 5 299.95
HW333 USB System Architecture
Universal Serial Bus System Architecture, Second Edition, based on the 2.0 version of the Universal Serial Bus specification, provides in-depth coverage and a detailed discussion of USB. It focuses on the USB protocol, signaling environment, and electrical specifications, along with the hardware/software interaction required to configure and access USB devices.
$49.99 1 49.99
HW444 Designing Embedded Hardware
Designing Embedded Hardware is a book about designing small machines for embedded applications. There are many books on the market dedicated to writing code for particular microprocessors, or that stress the philosophy of embedded system design without providing any practical information. This book steers a middle path, telling you what you need to know to create your own products, and distilling much of the lore of embedded systems design into a single volume. It shows you how to build a complete embedded system, add peripherals, and connect your system to other devices.
$44.95 3 134.85
HW555 Contemporary Logic Design
Contemporary Logic Design introduces a wide range of software tools including schematic capture, logic simulation, Boolean minimization, multi-level minimization and state assignment. Links the traditional techniques of logic design (such as Karnaugh maps and breadboard techniques) with real-world design examples. Provides comprehensive, early coverage of programmable logic including ROMs, PALs, and PLAs. Includes a variety of examples, exercises, problems, and case studies that illustrate real design problems and challenge the reader to develop practical solutions using modern design tools.
$102.95 2 205.90
        Total: $930.61

Displaying Scrolling Fields

A GridView presents data fields along the rows of a table. Sometimes, though, the amount of data is too large to fit comfortably inside a table cell. In the above example, the BookDescription field is a case in point. If displayed in a BoundField, the size of the field expands vertically to encompass the amount of text being displayed, making for a very lengthy and awkward-looking table. A better solution is to display lengthy text fields inside scrollable fields all of the same dimensions, as is done in the example.

A TemplateField can include a Label control inside a Panel control to create a scrollable field. The Panel is given Width and Height settings for the fixed size of the display area, along with the ScrollBars property to introduce scroll bars. Text is bound to the Label control inside this scrollable area. Below is shown code for the TemplateField used to display book descriptions in the example GridView.

<asp:TemplateField
  HeaderText="Book Description">
  <ItemTemplate>
  <asp:Panel Width="230px" Height="40px" ScrollBars="Vertical"
  Runat="Server">
    <asp:Label Font-Size="8pt" Font-Name="Verdana"
    Text='<%# Eval("BookDescription") %>' Runat="Server"/>
  </asp:Panel>
  </ItemTemplate>
</asp:TemplateField>

In the current example, ScrollBars is set to "Vertical" to always display a vertical scroll bar whether needed or not to display the enclosed text. An option is to set this property to "Auto" to display a vertical scroll bar only if needed.

dipa ahuja replied to April June on 16-Nov-11 02:46 AM


Steps:
1. download the jquery files from 
http://beckelman.net/post/2008/10/07/Truncate-Lengthy-Text-for-Cleaner-Display-in-ASPNET-ListView-Using-jQuery.aspx
2. Add files :
<link href="yui.css" rel="stylesheet" type="text/css" />
<script src="jquery-1.4.3.min.js" type="text/javascript"></script>
<script src="jquery.truncator-1.0.js" type="text/javascript"></script>
3. Add Script: 
<script type="text/javascript">
  $(document).ready(function () {
  $('.note').truncate({ max_length: 4});
  });   
</script>
4.  Add a cssClass attribute to the filed you want to truncate:
<asp:Label ID="Label2" runat="server" CssClass="note" Text='<%# Bind("name") %>'/>
Done!