By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,360 Members | 3,011 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,360 IT Pros & Developers. It's quick & easy.

"System.Web.HttpException: External component has thrown an exception" if OnSortCommand attribute is present in a datagrid control

P: n/a
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.ThrowIfCompile rErrors(CompilerResults
results, CodeDomProvider codeProvider, CodeCompileUnit sourceData,
String sourceFile, String sourceString)\r\n at
System.Web.Compilation.BaseCompiler.GetCompiledTyp e()\r\n at
System.Web.Compilation.PageCompiler.CompilePageTyp e(PageParser
pageParser)\r\n at System.Web.UI.PageParser.CompileIntoType()\r\n
at
System.Web.UI.TemplateParser.GetParserCacheItemThr oughCompilation()\r\n
--- End of inner exception stack trace ---\r\n at
System.Web.UI.TemplateParser.GetParserCacheItemInt ernal(Boolean
fCreateIfNotFound)\r\n at
System.Web.UI.TemplateParser.GetParserCacheItem()\ r\n at
System.Web.UI.TemplateControlParser.CompileAndGetP arserCacheItem(String
virtualPath, String inputFile, HttpContext context)\r\n at
System.Web.UI.TemplateControlParser.GetCompiledIns tance(String
virtualPath, String inputFile, HttpContext context)\r\n at
System.Web.UI.PageParser.GetCompiledPageInstanceIn ternal(String
virtualPath, String inputFile, HttpContext context)\r\n at
System.Web.UI.PageHandlerFactory.GetHandler(HttpCo ntext context, String
requestType, String url, String path)\r\n at
System.Web.HttpApplication.MapHttpHandler(HttpCont ext context, String
requestType, String path, String pathTranslated, Boolean
useAppConfig)\r\n at
System.Web.MapHandlerExecutionStep.System.Web.Http Application+IExecutionStep.Execute()\r\n
at System.Web.HttpApplication.ExecuteStep(IExecutionS tep 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>

Nov 10 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.