Extending DataGrid

J

jarod

Hello,

I'm having difficulty with trying to extend the
functionality of the DataGrid Control. I created the
child class, but can't figure out how to access all the
functionality of the DataGrid class form the aspx file.
When using the <asp:TemplateColumn> tag, I get the
following error:

Description: An error occurred during the parsing of a
resource required to service this request. Please review
the following specific parse error details and modify your
source file appropriately.

Parser Error Message: Type 'DDW.DDWDataGrid' does not have
a property named 'asp:TemplateColumn'.




--------------------------------------------------------
-------------- cs file -------------------------------
--------------------------------------------------------

// DDWDataGrid.cs
//

namespace DDW {
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Data;

/// <summary>
/// Summary description for DDWDataGrid.
/// </summary>
public class DDWDataGrid :
System.Web.UI.WebControls.DataGrid {

/// <summary>
/// Creates a new instance of DDWDataGrid
/// </summary>
public DDWDataGrid() : base() {

}

protected override void Render
(HtmlTextWriter output)
{
output.Write( "overide!" );
base.Render(output);
}
}
}



--------------------------------------------------------
-------------- aspx file -------------------------------
--------------------------------------------------------

<%@ Page Language="C#" autoeventwireup="True" %>
<%@ Register TagPrefix="DDW" NameSpace="DDW"
Assembly="DDWDataGrid" %>
<%@ import Namespace="System.Data" %>
<script runat="server">

ICollection CreateDataSource()
{
DataTable dt = new DataTable();
DataRow dr;
Random Rand_Num = new Random();

dt.Columns.Add(new DataColumn("IntegerValue",
typeof(Int32)));
dt.Columns.Add(new DataColumn("StringValue",
typeof(string)));
dt.Columns.Add(new DataColumn("CurrencyValue",
typeof(double)));

for (int i = 0; i < 15; i++)
{
dr = dt.NewRow();

dr[0] = i;
dr[1] = "Item " + i.ToString();
dr[2] = 1.23 * Rand_Num.Next(1, 15);

dt.Rows.Add(dr);
}

DataView dv = new DataView(dt);
dv.Sort=SortExpression;
return dv;
}

void Page_Load(Object sender, EventArgs e)
{

if (!IsPostBack)
{
ItemsGrid.DataSource = CreateDataSource();
ItemsGrid.DataBind();
}

}

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<h3>DataGrid Sorting Example
</h3>
<DDW:DDWDataGrid id="ItemsGrid" runat="server"
BorderColor="black" BorderWidth="1" CellPadding="3"
AllowSorting="true" OnSortCommand="Sort_Grid"
OnEditCommand="Edit_Grid" HeaderStyle-BackColor="#00aaaa"
ShowFooter="True" AutoGenerateColumns="true">
<asp:TemplateColumn>
<HeaderTemplate>
<b> IntegerValue </b>
</HeaderTemplate>
</asp:TemplateColumn>
</DDW:DDWDataGrid>
</form>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top