Click here to Skip to main content
11,634,453 members (73,352 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
I am developing a websie in asp.net and I have done a GridView Binding.when i run the website or program then i find this error:---


"error-exception has been thrown by the target of an invocation"
Give me the proper answer.
my sample code for the binding is given below:--

In aspx page:-
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
            CellPadding="4" ForeColor="#333333" GridLines="Horizontal"
        Width="743px">
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" HorizontalAlign="Center" />
        <Columns>
            <asp:TemplateField HeaderText="UserId" Visible="false">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("userid") %>'></asp:TextBox>
                </EditItemTemplate>
<HeaderTemplate>
            Field of Work2
 
</HeaderTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("userid") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
 

         <asp:TemplateField>
        <HeaderTemplate>
            Field of Work2
        </HeaderTemplate>
        <ItemTemplate>
            <asp:Label ID="Label3" runat="server" Text='<%#Bind("fieldofwork1") %>'></asp:Label>
            </ItemTemplate>
        <EditItemTemplate>
            <asp:TextBox ID="TextBox3" runat="server" Text='<%#Bind("fieldofwork1") %>'></asp:TextBox>
 
        </EditItemTemplate>
        </asp:TemplateField>
 
          <asp:TemplateField>
        <HeaderTemplate>
            From
        </HeaderTemplate>
        <ItemTemplate>
            <asp:Label ID="Label3" runat="server" Text='<%#Bind("[[From]1]") %>'></asp:Label>
        </ItemTemplate>
        <EditItemTemplate>
            <asp:TextBox ID="TextBox3" runat="server" Text='<%#Bind("[[From]]1]") %>'></asp:TextBox>
        </EditItemTemplate>
        </asp:TemplateField>
 
        <asp:TemplateField>
        <HeaderTemplate>
            To
        </HeaderTemplate>
        <ItemTemplate>
            <asp:Label ID="Label3" runat="server" Text='<%#Bind("[[To]]1]") %>'></asp:Label>
        </ItemTemplate>
        <EditItemTemplate>
            <asp:TextBox ID="TextBox3" runat="server" Text='<%#Bind("[[To]]1]") %>'></asp:TextBox>
        </EditItemTemplate>
        </asp:TemplateField>
                                         <asp:TemplateField>
        <HeaderTemplate>
            Specialization
        </HeaderTemplate>
        <ItemTemplate>
            <asp:Label ID="Label3" runat="server" Text='<%#Bind("specialization1") %>'></asp:Label>
        </ItemTemplate>
        <EditItemTemplate>
            <asp:TextBox ID="TextBox3" runat="server" Text='<%#Bind("specialization1") %>'></asp:TextBox>
        </EditItemTemplate>
        </asp:TemplateField>
                                         <asp:TemplateField>
        <HeaderTemplate>
            Organization
        </HeaderTemplate>
        <ItemTemplate>
            <asp:Label ID="Label3" runat="server" Text='<%#Bind("organization1") %>'></asp:Label>
        </ItemTemplate>
        <EditItemTemplate>
            <asp:TextBox ID="TextBox3" runat="server" Text='<%#Bind("organization1") %>'></asp:TextBox>
        </EditItemTemplate>
        </asp:TemplateField>

</Columns>
           <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
           <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
           <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
           <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
           <EditRowStyle BackColor="#999999" />
           <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
       </asp:GridView>
Posted 20-Sep-11 20:56pm
Comments
arathi_suresh at 21-Sep-11 3:20am
   
Show the binding code
hitech_ssc at 21-Sep-11 4:22am
   
if you dont mind place a break point and debug your code ...
tell us where you are getting the error message...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Root cause for this issue might be the solution file CPU-flavor references become corrupted. To fix this issue:

1. Open the .sln file in notepad
2. Change All References to"AnyCPU"
3. Save
4. Open the solution again
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

it is not a web specific error, well ...

1.ensure that a value is being returned fron the databse. Otherwise you will get this error.

2.if u r using ajax and script manager then: Disable the ajax for a moment (EnablePartialRendering="false" on the scriptmanager).
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

This error is throwned when a control is not supported by Asp.Net..

That is if you are using a control developed for windows in Asp.Net then this error is throwned
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Check the inner exception of the error for specific error message. I had the same problem and it was dues to insufficient parameters being passed to a stored procedure.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 8,758
1 Sergey Alexandrovich Kryukov 8,264
2 Mika Wendelius 6,755
3 F-ES Sitecore 2,344
4 Suvendu Shekhar Giri 2,095


Advertise | Privacy | Mobile
Web01 | 2.8.150728.1 | Last Updated 22 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100