Microsoft KB Archive/916443

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

Article ID: 916443

Article Last Modified on 8/22/2006

-

APPLIES TO


 * Microsoft ASP.NET 2.0

-





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.



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. ' runat=&quot;server&quot; Text='<%# Eval(&quot;au_fname&quot;, &quot;go/{0}&quot;) %>'>  Note  is a placeholder for the name of the Hyperlink control. is a placeholder for name of the data source field that contains &quot;first name&quot; information. You must change these names to match your application.



RESOLUTION
To resolve this problem, use the following code to replace the code that is generated by Visual Web Developer. ' runat=&quot;server&quot;>  Note  is a placeholder for the name of the Hyperlink control. is a placeholder for name of the data source field that contains &quot;last name&quot; information. You must change these names to match your application.



Steps to reproduce this problem
 Start Visual Web Developer. Create a new ASP.NET Web site. To do this, follow these steps:  In the File menu, click New Web Site. 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.</li></ol> </li>  Replace the code in the Default.aspx file by using the following code. <%@ Page Language=&quot;C#&quot; %> <!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.1//EN&quot; &quot;http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd&quot;> <script runat=&quot;server&quot;> <html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; > <head runat=&quot;server&quot;> Untitled Page <form id=&quot;form1&quot; runat=&quot;server&quot;> <asp:GridView AllowPaging=&quot;True&quot; AutoGenerateColumns=&quot;False&quot; DataKeyNames=&quot;au_id&quot; DataSourceID=&quot;SqlDataSource2&quot; ID=&quot;GridView1&quot; PageSize=&quot;4&quot; runat=&quot;server&quot; AllowSorting=&quot;True&quot;> <Columns> <asp:BoundField DataField=&quot;au_id&quot; HeaderText=&quot;au_id&quot; ReadOnly=&quot;True&quot; SortExpression=&quot;au_id&quot; AccessibleHeaderText=&quot;sample&quot;> </asp:BoundField> <asp:BoundField DataField=&quot;au_lname&quot; HeaderText=&quot;au_lname&quot; SortExpression=&quot;au_lname&quot;> </asp:BoundField> <asp:BoundField DataField=&quot;au_fname&quot; HeaderText=&quot;au_fname&quot; SortExpression=&quot;au_fname&quot;> </asp:BoundField> <asp:BoundField DataField=&quot;phone&quot; HeaderText=&quot;phone&quot; SortExpression=&quot;phone&quot;></asp:BoundField> </asp:HyperLinkField> </Columns> </asp:GridView> <asp:SqlDataSource ConnectionString=&quot;data source=myDataSource;initial catalog=pubs;user=myUserName;pwd=myPassword&quot; ID=&quot;SqlDataSource2&quot; runat=&quot;server&quot; SelectCommand=&quot;SELECT * FROM authors&quot; CacheExpirationPolicy=&quot;Sliding&quot; UpdateCommand=&quot;update test set &#13;&#10;path=@path, &#13;&#10;name=@name &#13;&#10;where id1=@id1&quot; OldValuesParameterFormatString=&quot;{0}&quot;></asp:SqlDataSource> Note Change the data source connection information in this code to match your data source. In this code,  is a placeholder for the name of the data source,   is a placeholder for the user name that is used to connect to the data source, and   is a placeholder for a password. </li> Click Design to switch to Design view, and then click the GridView control.</li> Click the smart tag icon to open the GridView Tasks menu, and then click Edit Columns.</li> In the Fields dialog box, click The Link in the Selected Fields list, and then click Convert this field into a TemplateField.</li> Click OK.</li> In the Debug menu, click Start Debugging.</li></ol>

Keywords: kbasp kbconversion kbtshoot kbprb KB916443

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.