无法删除 GridView 中的行,为什么?
早上好, 拜托,我有依赖的 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>
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" />
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用属性 DatakeyNames 在 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.
首先,您还没有向 gridview 提供
DataKeyNames
。其次,您没有提供删除方法参数
First of all you have not provided
DataKeyNames
to your gridview. Secondly you have not providedDelete method parameter