Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

Error message when you try to run an ASP.NET 2.0 Web application: "An unhandled exception occurred during the execution of the current web request"


View products that this article applies to.

Symptoms

When you try to run a Microsoft ASP.NET 2.0 Web application that is built on the Microsoft .NET Framework 2.0, you receive the following error message:
Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
This problem occurs when you try to convert a hyperlink field by clicking the Convert this field into a TemplateField link in the Fields dialog box in Microsoft Visual Web Developer.

↑ Back to the top


Cause

This problem is caused by incorrect code that is generated by Visual Web Developer. When you click the Convert this field into a TemplateField link in the Fields dialog box, code that resembles the following is generated.
<asp:HyperLink ID="HyperLink1"
    NavigateUrl='<%# Eval("au_fname", "http://{0}/{1}/{2}") %>' runat="server" Text='<%# Eval("au_fname", "go/{0}") %>'>
</asp:HyperLink>
Note HyperLink1 is a placeholder for the name of the Hyperlink control. au_fname is a placeholder for name of the data source field that contains "first name" information. You must change these names to match your application.

↑ Back to the top


Resolution

To resolve this problem, use the following code to replace the code that is generated by Visual Web Developer.
<asp:HyperLink ID="HyperLink1"
    NavigateUrl='<%# String.Format("http://{0}/{1}/{2}", DataBinder.Eval(Container.DataItem,"au_fname"),
    DataBinder.Eval(Container.DataItem,"au_lname"),DataBinder.Eval(Container.DataItem,"au_id")) %>' runat="server">
</asp:HyperLink>
Note HyperLink1 is a placeholder for the name of the Hyperlink control. au_lname is a placeholder for name of the data source field that contains "last name" information. You must change these names to match your application.

↑ Back to the top


More information

Steps to reproduce this problem

  1. Start Visual Web Developer.
  2. Create a new ASP.NET Web site. To do this, follow these steps:
    1. In the File menu, click New Web Site.
    2. In the New Web Site dialog box, click ASP.NET Web Site, and then click OK.

      Note A new Web site project is created. The Default.aspx file is opened in the Source view.
  3. Replace the code in the Default.aspx file by using the following code.
    <%@ Page Language="C#" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <script runat="server">
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:GridView AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="au_id"
                DataSourceID="SqlDataSource2" ID="GridView1" PageSize="4" runat="server" AllowSorting="True">
                <Columns>
                    <asp:BoundField DataField="au_id" HeaderText="au_id" ReadOnly="True" SortExpression="au_id" AccessibleHeaderText="sample">
                    </asp:BoundField>
                    <asp:BoundField DataField="au_lname" HeaderText="au_lname" SortExpression="au_lname">
                    </asp:BoundField>
                    <asp:BoundField DataField="au_fname" HeaderText="au_fname" SortExpression="au_fname">
                    </asp:BoundField>
                    <asp:BoundField DataField="phone" HeaderText="phone" SortExpression="phone"></asp:BoundField>
                    <asp:HyperLinkField DataNavigateUrlFields="au_fname,au_lname,au_id" DataNavigateUrlFormatString="http://{0}/{1}/{2}"
                        DataTextField="au_fname" DataTextFormatString="Name: {0}" HeaderText="The Link"
                        SortExpression="au_fname"></asp:HyperLinkField>
                </Columns>
            </asp:GridView>
            <asp:SqlDataSource ConnectionString="data source=myDataSource;initial catalog=pubs;user=myUserName;pwd=myPassword"
                ID="SqlDataSource2" runat="server" SelectCommand="SELECT * FROM authors" CacheExpirationPolicy="Sliding" UpdateCommand="update test set &#13;&#10;path=@path, &#13;&#10;name=@name &#13;&#10;where id1=@id1" OldValuesParameterFormatString="{0}"></asp:SqlDataSource>
        </form>
    </body>
    </html>
    
    Note Change the data source connection information in this code to match your data source. In this code, myDataSource is a placeholder for the name of the data source, myUserName is a placeholder for the user name that is used to connect to the data source, and myPassword is a placeholder for a password.
  4. Click Design to switch to Design view, and then click the GridView control.
  5. Click the smart tag icon to open the GridView Tasks menu, and then click Edit Columns.
  6. In the Fields dialog box, click The Link in the Selected Fields list, and then click Convert this field into a TemplateField.
  7. Click OK.
  8. In the Debug menu, click Start Debugging.

↑ Back to the top


Properties

Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.

↑ Back to the top


Keywords: KB916443, kbprb, kbtshoot, kbconversion, kbasp

↑ Back to the top

Article Info
Article ID : 916443
Revision : 4
Created on : 8/22/2006
Published on : 8/22/2006
Exists online : False
Views : 295