DELETE 명령에 매개 변수를 전달할 때 몇 가지 문제가 발생하며 어떻게 작동하는지 잘 이해하지 못하는 것 같습니다.SQLDataSource 매개 변수를 가져 오려면 DeleteCommand
<asp:SqlDataSource ID="sdsPropertyList"
runat="server"
ProviderName="<%$ appSettings:ProviderName %>"
ConnectionString="<%$ appSettings:ConnectionString %>"
SelectCommand="selPropertyByAcntID"
SelectCommandType="StoredProcedure"
OnSelecting="sdsPropertyList_Selecting"
OnSelected="sdsPropertyList_Selected"
DeleteCommand="delPropertyByPropID"
DeleteCommandType="StoredProcedure"
OnDeleting="sdsPropertyList_Deleting"
OnDeleted="sdsPropertyList_Deleted">
<SelectParameters>
<asp:Parameter Name="in_acntID" Type="Int32" DefaultValue="0" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="in_acntID" Type="Int32" DefaultValue="0" />
<asp:Parameter Name="in_propID" Type="Int32" DefaultValue="0" />
</DeleteParameters>
</asp:SqlDataSource>
<asp:GridView ID="gvProperty" runat="server" DataSourceID="sdsPropertyList"
AutoGenerateColumns="false" CssClass="gvPropList">
<Columns>
<asp:BoundField HeaderText="ID" InsertVisible="true" DataField="prop_id" ReadOnly="true" Visible="False" />
<asp:BoundField HeaderText="Property" DataField="prop_title"
ItemStyle-CssClass="gvPropTitle" >
<ItemStyle CssClass="gvPropTitle" />
</asp:BoundField>
<asp:BoundField HeaderText="Units" DataField="unitCount"
ItemStyle-CssClass="gvUnitCount" >
<ItemStyle CssClass="gvUnitCount" />
</asp:BoundField>
<asp:BoundField DataField="prop_lastmodified" HeaderText="Last Modified"
ItemStyle-CssClass="gvDate" DataFormatString="{0:M/dd/yyyy hh:mm tt}" >
<ItemStyle CssClass="gvDate" />
</asp:BoundField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lbtnEdit" runat="server" CommandName="EditRecord" Text="Edit" CommandArgument='<%# Eval("prop_id") %>'></asp:LinkButton>
<asp:LinkButton ID="lbtnDelete" runat="server" CommandName="Delete" Text="Delete" CommandArgument='<%# Eval("prop_id") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lbtnAdd" runat="server" CommandName="AddRecord" Text="Add" CommandArgument='<%# Eval("prop_id") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle CssClass="headerPropList"/>
<RowStyle CssClass="gvPropRow" />
</asp:GridView>
protected void sdsPropertyList_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
int userID = Convert.ToInt32(Page.User.Identity.Name);
if (userID != 0)
e.Command.Parameters["in_acntID"].Value = userID;
}
protected void sdsPropertyList_Deleting(object sender, SqlDataSourceCommandEventArgs e)
{
int userID = Convert.ToInt32(Page.User.Identity.Name);
if (userID != 0)
{
e.Command.Parameters["in_acntID"].Value = userID;
}
}
SELECT 문은 userID의 입력 매개 변수 하나를 필요로합니다. 그러나 DELETE 문에는 2 개의 매개 변수 입력이 필요합니다. in_acntID = userID in_propID = 바운드 필드 데이터 필드 prop_id
내가 뭘 잘못하고 있니? SqlDataSource 수준에서 정의 된 경우 CommandName 및 CommandArgument를 ItemTemplate 수준에서 전달해야합니까? 있는 gridview
UPDATE
을 한 후로부터 행을 제거
- 삭제 기록 : 나는 삭제 버튼은 다음과 달성하고자하는 몇 가지 추가 연구, 그 발견했습니다, Boundfield에 대한 매개 변수 및 HeaderText에 대한 이름은 귀하의 gridview 내의 값이 SQL com에 의해 사용될 수 있도록 동일해야합니다 데이터 소스의 mands.
초기 선택 명령을 제외하고는 모든 참조 코드를 제거했습니다.
모두 현재 근면하게 작업 중입니다.
DataKeyNames = "prop_id, acnt_id"를 추가하려고했지만 원하는 결과를 얻지 못했습니다. 값을 datakeynames로 전달할 때 sdsPropertyList_Deleting 명령에 매개 변수로 전달되는 방법은 무엇입니까? – Rick
이 대답은 나를위한 해결책이었습니다. 당신의 해결책은 다른 문제로 인한 것이지만, 사람들이 매개 변수로 포함 시키길 원한다면 항상 모든 데이터 키를 포함하도록 상기시키고 싶습니다.이 답변을 주셔서 감사합니다! – SelAromDotNet