What is the syntax for datagrid and specifying columns ?

Answer Posted / venugopal

The DataGrid is a Web server control that is used for data
display. This control provides the easy way to bind the
data from the database to the user in a user-friendly
manner. The DataGrid control renders a tabular, data-bound
grid. The DataGrid control displays the fields of a data
source as columns in a table. Each row in the DataGrid
control represents a record in the data source. The
DataGrid control supports selection, editing, deleting,
paging, and sorting.

The datagrid has the following column types:


EditCommandColumn : Encapsulates the most common edit
commands (Edit, Update, Cancel) in a predefined column
type.
HyperLinkColumn : Creates a column with a set of
hyperlinks that are bound to the value of a data field. For
example, a grid that displays a list of orders can include
a hyperlink column where the OrderID field is rendered as a
hyperlink to a page that displays the details for the
order.
BoundColumn :Creates column bound to a field in the
data source and rendered in a table cell using styles. This
is the default column type for the DataGrid control.
BottonColumn : Creates a column that contains a user
defined command button, such as Add or Remove, for each
item in the column.
TemplateColumn : Creates a column that allows you to
define the layout of controls using templates for custom
HTML elements and controls.

The syntax for the datagrid and columns is as fallows

<asp:datagrid id="dgPopularFAQs" runat="server"
AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="FAQID" ItemStyle-
Width="10%"
ItemStyle-HorizontalAlign="Center"
HeaderText="FAQ ID" />

<asp:TemplateColumn HeaderText="FAQ Information">
<ItemTemplate>
<table border="0">
<tr>
<td align="right"><b>Description:</b></td>
<td><%# DataBinder.Eval
(Container.DataItem, "Description") %></td>
</tr>
<tr>
<td align="right"><b>Category Name:</b></td>
<td><%# DataBinder.Eval
(Container.DataItem, "CatName") %></td>
</tr>
<tr>
<td align="right"><b>View Count:</b></td>
<td><%# DataBinder.Eval
(Container.DataItem, "ViewCount", "{0:#,###}") %>
</td>
</tr>
</table>
</ItemTemplate>

</Columns>
</asp:datagrid>

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Where do the cookie state and session state information be stored?

501


What is the typical session identifier?

567


How can we use Web API with ASP.NET Web Form?

640


What is postback request?

548


What are Caching techniques in .NET

590






What is routing in MVC?

589


Is asp.net and .net the same?

508


Explain global assembly cache.

567


What is a SESSION and APPLICATION object?

572


What is a postback url?

489


Which method is used to enforce garbage collection in .net?

421


What does postback mean?

529


When cookie will expire?

580


What is the significance of attaching a profile while creating a user?

559


What are the features of asp.net mvc?

521