Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法在gridview上调用更新函数_C#_Asp.net_Gridview_Objectdatasource_Aspxgridview - Fatal编程技术网

C# 无法在gridview上调用更新函数

C# 无法在gridview上调用更新函数,c#,asp.net,gridview,objectdatasource,aspxgridview,C#,Asp.net,Gridview,Objectdatasource,Aspxgridview,我每次调用更新函数都会遇到问题, 我相信问题的根源是因为这个函数得到了对象参数, 从衍射源得到一个参数,我现在不这么做 这就是错误: GridView代码: <asp:GridView ID="gvAnimals" runat="server" AutoGenerateColumns="False" CellPadding="4" DataSourceID="ObjectDataSourceAnimals" ForeColor="#333333" GridLines="None" Dat

我每次调用更新函数都会遇到问题, 我相信问题的根源是因为这个函数得到了对象参数, 从衍射源得到一个参数,我现在不这么做

这就是错误:

GridView代码:

<asp:GridView ID="gvAnimals" runat="server" AutoGenerateColumns="False" CellPadding="4" DataSourceID="ObjectDataSourceAnimals" ForeColor="#333333" GridLines="None" DataKeyNames="animalId">
                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                <Columns>
                    <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                    <asp:BoundField DataField="animalId" HeaderText="animalId" SortExpression="animalId" />
                    <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
                    <asp:CheckBoxField DataField="vertebrates" HeaderText="vertebrates" SortExpression="vertebrates" />
                    <asp:CheckBoxField DataField="vegetarian" HeaderText="vegetarian" SortExpression="vegetarian" />
                    <asp:CheckBoxField DataField="terrestrial" HeaderText="terrestrial" SortExpression="terrestrial" />
                    <asp:BoundField DataField="kind" HeaderText="kind" SortExpression="kind" />
                    <asp:BoundField DataField="avgWeight" HeaderText="avgWeight" SortExpression="avgWeight" />
                    <asp:BoundField DataField="avgHeight" HeaderText="avgHeight" SortExpression="avgHeight" />
                    <asp:BoundField DataField="infoAdress" HeaderText="infoAdress" SortExpression="infoAdress" />
                    <asp:BoundField DataField="imageAdress" HeaderText="imageAdress" SortExpression="imageAdress" />
                </Columns>
                <EditRowStyle BackColor="#999999" />
                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                <SortedAscendingCellStyle BackColor="#E9E7E2" />
                <SortedAscendingHeaderStyle BackColor="#506C8C" />
                <SortedDescendingCellStyle BackColor="#FFFDF8" />
                <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
            </asp:GridView>
            <asp:ObjectDataSource ID="ObjectDataSourceAnimals" runat="server" DeleteMethod="DeleteAnimal" OldValuesParameterFormatString="original_{0}" SelectMethod="GetAllAnimals" TypeName="BLProject.Animal" UpdateMethod="UpdateAnimal" DataObjectTypeName="BLProject.Animal">
                <DeleteParameters>
                    <asp:Parameter Name="a" Type="Object" />
                    <asp:SessionParameter Name="newsAdress" SessionField="Adress" Type="String" />
                </DeleteParameters>
                <SelectParameters>
                    <asp:ControlParameter ControlID="textSearch" Name="Search" PropertyName="Text" Type="String" />
                    <asp:ControlParameter ControlID="dropdownlistAnimalToSearch" Name="type" PropertyName="SelectedValue" Type="String" />
                </SelectParameters>
                <UpdateParameters>
                    <asp:Parameter Name="a" Type="Object" />
                    <asp:SessionParameter DefaultValue="D:\\project\\Ilan Project 29-11\\Web\\NewsInfo" Name="newsAdress" SessionField="Adress" Type="String" />
                </UpdateParameters>
            </asp:ObjectDataSource>
Animal a是栅格视图通过使用select函数获得的对象参数, 但是adress是该函数从会话源获取的另一个参数。 然而,由于我添加了这个参数,我有了这个新的错误


谢谢。

您可以这样做:

用这个改变你的方法

public void UpdateAnimal(int animalId, string name, bool vertebrates, bool vegetarian, string newsAdress)
    {

    }
以及您的ObjectDataSource

<asp:ObjectDataSource ID="ObjectDataSourceAnimals" runat="server" DeleteMethod="DeleteAnimal" SelectMethod="GetAllAnimals" TypeName="BLProject.Animal" UpdateMethod="UpdateAnimal">
            <DeleteParameters>
                <asp:Parameter Name="a" Type="Object" />
                <asp:SessionParameter Name="newsAdress" SessionField="Adress" Type="String" />
            </DeleteParameters>
            <SelectParameters>
                <asp:ControlParameter ControlID="textSearch" Name="Search" PropertyName="Text" Type="String" />
                <asp:ControlParameter ControlID="dropdownlistAnimalToSearch" Name="type" PropertyName="SelectedValue" Type="String" />
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="animalId" Type="Int32"/>
                .......the other fields from Animal that you want to update
                <asp:Parameter Name="name" Type="String"/>
                <asp:Parameter Name="vegetarian" Type="Boolean"/>
                <asp:Parameter Name="vertebrates" Type="Boolean"/>
                <asp:SessionParameter DefaultValue="D:\\project\\Ilan Project 29-11\\Web\\NewsInfo" Name="newsAdress" SessionField="Adress" Type="String" />
            </UpdateParameters>
        </asp:ObjectDataSource>

……要更新的其他动物字段
似乎在使用
DataObjectTypeName
时无法添加参数。解决方案是将编辑为参数的
动物
行的部分或全部属性与其他参数一起发送


如果要使用
OldValuesParameterFormatString=“original_{0}”
,请将此
int-original\u animalid
添加到方法输入参数。

是的,我知道,因为我向函数中添加了新参数,gridview还要求我手动添加对象参数。但是,我不知道怎么做,所以我相信这是我问题的根源:“你能检查一下你是否将这个添加到你的对象数据源DataObjectTypeName=“Animal”?我想我有这个:*编辑:我添加了这个:谢谢,但是现在我有了一个新的错误:TypeName不是你的类名,你在这里和msdn中更新了方法?我改变了,但仍然不起作用:我还尝试添加了一个:“DataObjectTypeName=”BLProject.Animal“但我有一个新错误:在使用参数时不要添加此DataObjectTypeName,如果不使用它,也要删除OldValuesParameterFormatString。”。我测试了这段代码,正在运行,再次检查方法参数类型必须与Animal类中的参数类型匹配。嘿,谢谢你的帮助,但是现在删除不起作用,它不发送所有参数,它只发送对象的id。
<asp:ObjectDataSource ID="ObjectDataSourceAnimals" runat="server" DeleteMethod="DeleteAnimal" SelectMethod="GetAllAnimals" TypeName="BLProject.Animal" UpdateMethod="UpdateAnimal">
            <DeleteParameters>
                <asp:Parameter Name="a" Type="Object" />
                <asp:SessionParameter Name="newsAdress" SessionField="Adress" Type="String" />
            </DeleteParameters>
            <SelectParameters>
                <asp:ControlParameter ControlID="textSearch" Name="Search" PropertyName="Text" Type="String" />
                <asp:ControlParameter ControlID="dropdownlistAnimalToSearch" Name="type" PropertyName="SelectedValue" Type="String" />
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="animalId" Type="Int32"/>
                .......the other fields from Animal that you want to update
                <asp:Parameter Name="name" Type="String"/>
                <asp:Parameter Name="vegetarian" Type="Boolean"/>
                <asp:Parameter Name="vertebrates" Type="Boolean"/>
                <asp:SessionParameter DefaultValue="D:\\project\\Ilan Project 29-11\\Web\\NewsInfo" Name="newsAdress" SessionField="Adress" Type="String" />
            </UpdateParameters>
        </asp:ObjectDataSource>