Spaces in column names are troublesome!
If you must use the space in the name, then the column name should be enclosed in square brackets
[]
.
Alternatively, remove the space from the
ColumnName
and use the
Caption
property of the
DataColumn
for the
friendly name.
===== Here's the C# of what I tried ==========
using System;
using System.Data;
using System.Web.UI;
namespace CP_WebDataColumn
{
public partial class About : Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Clear();
dt.Columns.Add("Apple");
DataColumn col = dt.Columns.Add("Apple 1");
DataRow mr = dt.NewRow();
mr["Apple"] = "Macbook";
mr["Apple 1"] = "ipod";
dt.Rows.Add(mr);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
Here's the About.aspx:
<%@ Page Title="About" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="About.aspx.cs" Inherits="CP_WebDataColumn.About" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<h2><%: Title %>.</h2>
<h3>Your application description page.</h3>
<p>Use this area to provide additional information.</p>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</asp:Content>