DataGrid Common concern Solutions

Source: Internet
Author: User
Tags data structures object model visual studio
datagrid| Solution | Problem Introduction
The DataGrid Web server control was a powerful tool for displaying information from data source. It is easy to use; can display editable data in a professional-looking grid by setting only a few properties. At the "Same time", the grid has a sophisticated object model that provides your with great flexibility on how to display th E data.

This is paper addresses some of the questions about customizing grid display that are commonly asked in newsgroups, on Web si TES, and in the other developer forums. The techniques described here is are sometimes quite simple and in other times somewhat involved. In each case, however, they address a question's how to go beyond the basic functionality of the DataGrid control.

This paper assumes so you are already familiar with the control-how to add it to a form and configure it to display DA Ta. You should also understand, you have a row in the grid into edit mode and other basic tasks. (For details, the DataGrid Web Server control.) Finally, you'll find it helpful to know how to work with templates-adding template columns to the grid and layout out Controls inside a template.

Windows forms versus Web forms DataGrid control
The Web forms DataGrid control isn't the same as the Windows forms equivalent. It is a common (and not unreasonable) assumption that they are the same control, or at least have identical. However, the entire programming paradigm for Web forms are quite different from this for Windows forms. For example, Web Forms pages perform a round trips to the server for any processing; They must manage state; They feature a very different data-binding model; And so on.

Because of differences, there are also significant differences in their respective controls, including the DataGrid Control. As a, the Web Forms DataGrid control includes less built-in functionality. A Few examples of the differences in the Web Forms DataGrid control are:

It does not inherently support master-detail data structures.
As with the other Web server controls, the it does not support two-way data binding. If you are want to update data, you must write the code to does this yourself.
Can only edit one row in a time.
It does not inherently support sorting, although it raises events for you can handle into order to sort the grid contents.
On the other hand:

Can bind the Web Forms DataGrid to any object that supports the IEnumerable interface.
The Web Forms DataGrid control supports paging.
It is easy to customize the appearance and layout of the Web forms DataGrid control as compared to the Windows forms one. (Details are provided later in this paper.)
Controlling Column Width, Height, and alignment
By default, the DataGrid control sizes rows and columns to fit the overall height and width so you have assigned to the Grid. Within The overall grid width, it sizes columns according to the width of the column heading text. All the data is displayed left-justified by default.

To control column characteristics, your should turn off auto column generation by setting the AutoGenerateColumns property to False. In fact, your should set this property to true only for short-term uses, such as quick proof-of-concept pages or Demonstrat ions. For production applications, you should add columns explicitly. The individual columns can be bound columns or template columns.

To set the column width, your create a STYLE element for this column and then set the element ' s width property to standard Units (say, pixels). The following example shows you what the HTML syntax as a looks element with its Width property set.

<asp:boundcolumn datafield= "title" sortexpression= "title"
headertext= "Title" >
<itemstyle width= "100px" ></ItemStyle>
</asp:BoundColumn>
Alternatively, you can did the same thing by setting the ItemStyle property directly in the element, as in the following ex Ample:

<asp:boundcolumn itemstyle-width= "100px" datafield= "title"
sortexpression= "title" headertext= "title" >
</asp:BoundColumn>
You can set alignment using the ' style element, setting it to ' right, ' left, ' and other values defined in the Horizontalal IGN enumeration. (in Visual Studio, alignment are available for individual columns in the Format tab to the grid's property builder.) The following is a example:

<asp:boundcolumn datafield= "title" sortexpression= "title"
headertext= "Title" >
<itemstyle width= "100px" horizontalalign= "right" ></ItemStyle>
</asp:bound

[1] [2] [3] [4] [5] [6] [7] [8] [9] [10] Next page >>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.