我有一個GridView與ItemTemplate按鈕,使用RowCommand函數來執行SQL。請注意,其中一個命令名稱爲「delete」來評估哪個按鈕被按下。這是否會導致GridView觸發RowDeleting事件?我認爲ASP .Net認爲我創建了一個自定義的刪除按鈕,因此觸發了該事件。我不使用這個事件,並且它試圖激發它,因爲它不存在。有沒有辦法禁用?ASP .Net如何識別GridView中的刪除按鈕?
的GridView
<asp:GridView ID="gv_uebersicht" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="Vertical" OnRowCommand="gv_uebersicht_RowCommand" OnRowDataBound="gv_uebersicht_RowDataBound" OnRowDeleting="gv_uebersicht_RowDeleting">
<AlternatingRowStyle BackColor="#CCCCCC" />
<Columns>
<asp:BoundField DataField="cockpit_id" HeaderText="cockpitid" />
<asp:BoundField DataField="lieferant" HeaderText="Lieferant" />
<asp:BoundField DataField="datei" HeaderText="Dateiname" />
<asp:BoundField DataField="status" HeaderText="Status" />
<asp:BoundField DataField="erstellzeit" HeaderText="Erstellzeit" />
<asp:BoundField DataField="meldung" HeaderText="Meldung" />
<asp:TemplateField HeaderText="Aktion">
<ItemTemplate>
<asp:Button ID="btn_delete" runat="server" CommandArgument='<%# Eval("cockpit_id") %>' CommandName='<%# "delete" %>' Text="Löschen" Visible='<%# Eval("status_id").ToString() == "2" || Eval("status_id").ToString() == "14" || Eval("status_id").ToString() == "67" || Eval("status_id").ToString() == "68" || Eval("status_id").ToString() == "999" || Eval("status_id").ToString() == "1" || Eval("status_id").ToString() == "69" %>' />
<asp:Button ID="btn_move" runat="server" CommandArgument='<%# Eval("cockpit_id") %>' CommandName='<%# "move" %>' Text="Move" Visible='<%# Eval("status_id").ToString() == "2" || Eval("status_id").ToString() == "14" || Eval("status_id").ToString() == "67" %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="status_id" HeaderText="statusid" />
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#808080" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#383838" />
</asp:GridView>
RowCommand功能
protected void gv_uebersicht_RowCommand(object sender, GridViewCommandEventArgs e)
{
string commandName = e.CommandName;
string commandArgument = e.CommandArgument.ToString();
lbl_msg.Text = "Die Datei " + DatabaseFunctions.GetScalar("SELECT VDB_LS_DATEI FROM VDB_LADESTATUS_COCKPIT WHERE VDB_LS_ID = " + commandArgument) + " wird " + (commandName == "move" ? "gemoved." : "gelöscht.");
ds.UpdateCommand = @"UPDATE VDB_LADESTATUS_COCKPIT
SET VDB_LS_STATUS_ID = 19
WHERE VDB_LS_ID = " + commandArgument;
ds.Update();
ds.InsertCommand = @"DECLARE
V_RC INTEGER;
BEGIN
V_RC := Val.Loeschen_Freigabe_Funktionen(P_Cockpit_ID => " + commandArgument + @",
P_Aktion => '" + commandName + @"');
END; ";
ds.Insert();
fill_gv_uebersicht();
}
添加您使用的代碼 –
@SruthiSuresh done – lenny
該文檔說是,觸發RowDeleting事件:https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview。 rowcommand(v = vs.110).aspx要禁用此行爲,顯而易見的解決方案是將命令名稱更改爲某個預定義名稱以外的名稱。 – Joe