Back to Devexpress

GridViewDataColumn.FieldName Property

aspnet-devexpress-dot-web-dot-gridviewdatacolumn-0607aaba.md

latest7.8 KB
Original Source

GridViewDataColumn.FieldName Property

Gets or sets the name of the database field assigned to the current column.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
[DefaultValue("")]
public virtual string FieldName { get; set; }
vb
<DefaultValue("")>
Public Overridable Property FieldName As String

Property Value

TypeDefaultDescription
StringString.Empty

A String value that specifies the name of a data field.

|

Remarks

To specify the text which is displayed within the column’s header, use the Caption property.

It is not allowed to set the FieldName property of several columns to the same data source’s field. The FieldName property should be set to a unique value.

For unbound columns, the FieldName should not refer to any field in ASPxGridView’s data source. Refer to the Unbound Columns topic for more information.

The example below demonstrates how to specify the display text for a cell:

aspx
<dx:ASPxGridView ID="grid" ClientInstanceName="grid" runat="server" KeyFieldName="ID" Width="100%" 
    OnCustomColumnDisplayText="grid_CustomColumnDisplayText">
    <Columns>
        <dx:GridViewDataTextColumn FieldName="From" Width="200px" />
        <dx:GridViewDataTextColumn FieldName="Subject" />
        <dx:GridViewDataDateColumn FieldName="Sent" Width="100px" />
        <dx:GridViewDataCheckColumn Caption="Attachment?" FieldName="HasAttachment" Width="100px" />
        <dx:GridViewDataTextColumn FieldName="Size" Width="80px" />
    </Columns>
</dx:ASPxGridView>
csharp
protected void grid_CustomColumnDisplayText(object sender, ASPxGridViewColumnDisplayTextEventArgs e) {
    if(e.Column.FieldName == "Size")
        e.DisplayText = Utils.FormatSize(e.Value);
}

Run Demo: ASPxGridView - Large Database

The following code snippets (auto-collected from DevExpress Examples) contain references to the FieldName property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

asp-net-web-forms-grid-create-report-based-on-grid-layout/CS/WebApplication1/ReportHelper.cs#L70

csharp
label.SizeF = ((XRTableCell)detailsInfo[col]).SizeF;
label.DataBindings.Add("Text", null, ((GridViewDataColumn)col).FieldName);
label.Summary = new XRSummary() { Running = SummaryRunning.Group };

asp-net-web-forms-grid-create-master-detail-grid-at-runtime/CS/MasterDetailGrids/Default.aspx.cs#L171

csharp
GridViewDataColumn colProductID = new GridViewDataColumn();
colProductID.FieldName = "ProductID";
colProductID.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.False;

asp-net-web-forms-grid-set-edit-form-values/CS/Solution/ClientSide.aspx.cs#L9

csharp
protected void grdProducts_CustomUnboundColumnData(object sender, DevExpress.Web.ASPxGridViewColumnDataEventArgs e) {
    if (e.Column.FieldName == "Total") {
        decimal price = (decimal)e.GetListSourceFieldValue("UnitPrice");

asp-net-web-forms-grid-initialize-editor-conditionally/CS/WebApplication_Grid/CustomEditItem.aspx.cs#L39

csharp
if (e.Column.FieldName == "DataValue") {
    switch (dataType) {

asp-net-web-forms-grid-create-hyperlink-column-at-runtime/CS/Default.aspx.cs#L37

csharp
GridViewDataTextColumn colID = new GridViewDataTextColumn();
colID.FieldName = "ID";
ASPxGridView1.Columns.Add(colID);

asp-net-web-forms-grid-create-report-based-on-grid-layout/VB/WebApplication1/ReportHelper.vb#L72

vb
label.SizeF = DirectCast(detailsInfo(col), XRTableCell).SizeF
label.DataBindings.Add("Text", Nothing, CType(col, GridViewDataColumn).FieldName)
label.Summary = New XRSummary() With {.Running = SummaryRunning.Group}

asp-net-web-forms-grid-create-master-detail-grid-at-runtime/VB/MasterDetailGrids/Default.aspx.vb#L175

vb
Dim colProductID As New GridViewDataColumn()
colProductID.FieldName = "ProductID"
colProductID.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.False

asp-net-web-forms-grid-set-edit-form-values/VB/Solution/ClientSide.aspx.vb#L12

vb
Protected Sub grdProducts_CustomUnboundColumnData(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxGridViewColumnDataEventArgs)
    If Equals(e.Column.FieldName, "Total") Then
        Dim price As Decimal = CDec(e.GetListSourceFieldValue("UnitPrice"))

asp-net-web-forms-grid-initialize-editor-conditionally/VB/WebApplication_Grid/CustomEditItem.aspx.vb#L37

vb
If e.Column.FieldName = "DataValue" Then
    Select Case dataType

asp-net-web-forms-grid-create-hyperlink-column-at-runtime/VB/Default.aspx.vb#L34

vb
Dim colID As GridViewDataTextColumn = New GridViewDataTextColumn()
colID.FieldName = "ID"
ASPxGridView1.Columns.Add(colID)

See Also

Grid View

GridViewDataColumn Class

GridViewDataColumn Members

DevExpress.Web Namespace