Click here to Skip to main content
15,911,711 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:-
XML
<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>


XML
</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
Comments
arathi_suresh 21-Sep-11 3:20am    
Show the binding code
hitech_s 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...

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
 
Share this answer
 
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).
 
Share this answer
 
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
 
Share this answer
 
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900