开发者

Can't delete row in GridView, why?

开发者 https://www.devze.com 2023-02-22 18:03 出处:网络
Good morning, please, I have dependent GridView and I want delete row, but it not working. Problem: method \'SmazOrdinacniDobu\' (for deleting) have type of parameter OrdinacniDoba, but this parameter

Good morning, please, I have dependent GridView and I want delete row, but it not working. Problem: method 'SmazOrdinacniDobu' (for deleting) have type of parameter OrdinacniDoba, but this parameter is empty... Why? :( (But update working fine...)

<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" /&开发者_运维百科gt;
    <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>


Bind the primary key of your datasource in the gridview with attribute DatakeyNames. In row command or row deleting event, find that key and delete the row.


First of all you have not provided DataKeyNames to your gridview. Secondly you have not provided Delete method parameter

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

精彩评论

暂无评论...
验证码 换一张
取 消