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

Discussion in 'ASP .Net' started by JT, Nov 10, 2006.

  1. JT

    JT Guest

    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>
    JT, Nov 10, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryan
    Replies:
    0
    Views:
    1,984
  2. =?Utf-8?B?QXNoYQ==?=
    Replies:
    0
    Views:
    382
    =?Utf-8?B?QXNoYQ==?=
    Jan 20, 2005
  3. Chad Devine
    Replies:
    2
    Views:
    3,536
    slickuser
    Feb 6, 2008
  4. Bostonasian
    Replies:
    1
    Views:
    803
    Joris Gillis
    Sep 18, 2005
  5. Edo van Vliet

    DataGrid OnSortCommand event not firing for some data

    Edo van Vliet, Jun 22, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    237
    Edo van Vliet
    Jun 22, 2004
Loading...

Share This Page