无法在GridView中删除行,为什么?

时间:2011-04-06 15:48:37

标签: c# .net asp.net gridview objectdatasource

早上好, 拜托,我有依赖GridView,我想要删除行,但它无法正常工作。 问题:方法'SmazOrdinacniDobu'(用于删除)具有参数OrdinacniDoba的类型,但此参数为空...为什么? :( (但更新工作正常...)

<asp:ObjectDataSource ID="odsOrdinacniHodiny" runat="server" 
    DataObjectTypeName="Praktik.DB.OrdinacniDoby.OrdinacniDoba" 
    DeleteMethod="SmazOrdinacniDobu" InsertMethod="VytvorNovou" 
    SelectMethod="VratVseOrdinaci" 
    TypeName="Praktik.DB.OrdinacniDoby.OrdinacniDoby" 
    UpdateMethod="UpravOrdinacniDobu">
<SelectParameters>
    <asp:ControlParameter ControlID="gwOrdinace" DefaultValue="0" Name="id" 
        PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:GridView ID="gwOrdinacniDoba" runat="server" AutoGenerateColumns="False" 
    EnableModelValidation="True" 
    onrowupdating="gwOrdinacniDoba_RowUpdating" 
    DataSourceID="odsOrdinacniHodiny" AutoGenerateDeleteButton="True" 
    EnableViewState="False">
<Columns>
    <asp:CommandField ButtonType="Image" 
        CancelImageUrl="~/App_Themes/ZdravotnickaZarizeni/design/cancel.png" 
        EditImageUrl="~/App_Themes/ZdravotnickaZarizeni/design/pencil.png" 
        ShowEditButton="True" 
        UpdateImageUrl="~/App_Themes/ZdravotnickaZarizeni/design/check.png" />
    <asp:BoundField DataField="IDOrdinacniDoby" HeaderText="ID Ordinační doby" />
    <asp:BoundField DataField="IDOrdinace" HeaderText="ID Ordinace" />
    <asp:BoundField DataField="PlatnostOd" HeaderText="Platnost od data" DataFormatString="{0:D}" />
    <asp:BoundField DataField="PlatnostDo" HeaderText="Platnost do data" DataFormatString="{0:D}" />
    <asp:BoundField DataField="Den" HeaderText="Den v týdnu" />
    <asp:BoundField DataField="RezervaceOd" HeaderText="Rezervace od" />
    <asp:BoundField DataField="RezervaceDo" HeaderText="Rezervace do" />
    <asp:BoundField DataField="OpakovatPoTydnech" HeaderText="Opakovat po týdnech" />
    <asp:CheckBoxField DataField="Pritomen" HeaderText="Přítomen?" />
    <asp:CommandField ButtonType="Image" 
        DeleteImageUrl="~/App_Themes/ZdravotnickaZarizeni/design/non.png" 
        ShowDeleteButton="True" />
</Columns>
</asp:GridView>

2 个答案:

答案 0 :(得分:0)

首先,您尚未向网格视图提供DataKeyNames。其次,您尚未提供Delete method parameter

 <DeleteParameters>
     <asp:Parameter Name="ParameterName" Type="Int32" />
 </DeleteParameters>

答案 1 :(得分:0)

使用属性DatakeyNames在gridview中绑定数据源的主键。在行命令或行删除事件中,找到该键并删除该行。