"System.Web.HttpException: External component has thrown an exception" if OnSortCommand attribute is

J

JT

This seems like it could be an asp.net bug. I am getting the following
exception when I add OnSortCommand attribute to a datagrid. I have
deleted the temp directories, rebooted etc and I have isolated it to
the OnSortCommands presence. When I use a code behind it doesn't fire
any events on the back end and the global error handler grabs it. I
put together a very simple example to illustrate the problem below. If
anyone has an idea of why this is happening I'd appreciate it.


+ _errorMessage {"System.Web.HttpException: External component has
thrown an exception. ---> System.Web.HttpCompileException: External
component has thrown an exception.\r\n at
System.Web.Compilation.BaseCompiler.ThrowIfCompilerErrors(CompilerResults
results, CodeDomProvider codeProvider, CodeCompileUnit sourceData,
String sourceFile, String sourceString)\r\n at
System.Web.Compilation.BaseCompiler.GetCompiledType()\r\n at
System.Web.Compilation.PageCompiler.CompilePageType(PageParser
pageParser)\r\n at System.Web.UI.PageParser.CompileIntoType()\r\n
at
System.Web.UI.TemplateParser.GetParserCacheItemThroughCompilation()\r\n
--- End of inner exception stack trace ---\r\n at
System.Web.UI.TemplateParser.GetParserCacheItemInternal(Boolean
fCreateIfNotFound)\r\n at
System.Web.UI.TemplateParser.GetParserCacheItem()\r\n at
System.Web.UI.TemplateControlParser.CompileAndGetParserCacheItem(String
virtualPath, String inputFile, HttpContext context)\r\n at
System.Web.UI.TemplateControlParser.GetCompiledInstance(String
virtualPath, String inputFile, HttpContext context)\r\n at
System.Web.UI.PageParser.GetCompiledPageInstanceInternal(String
virtualPath, String inputFile, HttpContext context)\r\n at
System.Web.UI.PageHandlerFactory.GetHandler(HttpContext context, String
requestType, String url, String path)\r\n at
System.Web.HttpApplication.MapHttpHandler(HttpContext context, String
requestType, String path, String pathTranslated, Boolean
useAppConfig)\r\n at
System.Web.MapHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute()\r\n
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean& completedSynchronously)"} System.Data.SqlTypes.SqlString




<%@ Page language="c#" %>
<%@ Import Namespace="System.Data" %>
<HTML>
<script language="C#" runat="server">

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

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

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

dr[0] = i;
dr[1] = "Item " + i.ToString();
dr[2] = DateTime.Now;
dr[3] = (i % 2 != 0) ? true : false;
dr[4] = 1.23 * (i+1);

dt.Rows.Add(dr);
}

DataView dv = new DataView(dt);
return dv;
}

void SortCommand_Click(object source, DataGridSortCommandEventArgs
e)
{
//dv.Sort = e.SortExpression;
//dgTransactions.DataBind();
}

void Page_Load(Object sender, EventArgs e) {
MyDataGrid.DataSource = CreateDataSource();
MyDataGrid.DataBind();
}

</script>
<body>
<h3><font face="Verdana">Specifying Columns in
DataGrid</font></h3>
<form runat="server" ID="Form1">
<ASP:DataGrid id="MyDataGrid" runat="server"
BorderColor="black" BorderWidth="1" GridLines="Both"
CellPadding="3" AllowSorting=true
OnSortCommand="SortCommand_Click" CellSpacing="0" Font-Name="Verdana"
Font-Size="8pt" HeaderStyle-BackColor="#aaaadd"
AutoGenerateColumns="true">
<Columns>
<asp:BoundColumn HeaderText="Integer"
DataField="IntegerValue" />
<asp:BoundColumn HeaderText="Date/Time"
DataField="DateTimeValue" />
<asp:BoundColumn HeaderText="String"
DataField="StringValue" />
<asp:BoundColumn HeaderText="True/False"
DataField="BoolValue" />
<asp:BoundColumn HeaderText="Price"
DataField="CurrencyValue" DataFormatString="{0:c}"
ItemStyle-HorizontalAlign="right" />
</Columns>
</ASP:DataGrid>
</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,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top