我有一個GridView來管理我的產品。我已經使用存儲過程爲它設置數據源。我也使用AutoGenerateDeleteButton
屬性來刪除我的GridView的每一行,現在我想用存儲過程來刪除我的GridView的行,當我點擊「刪除」LinkButton。我在其他有關ASP.NET的論壇上嘗試了一些教程,但沒有任何反應使用存儲過程而不是使用SqlDataSource更新和刪除GridView中的行ASP.NET C#
謝謝
我有一個GridView來管理我的產品。我已經使用存儲過程爲它設置數據源。我也使用AutoGenerateDeleteButton
屬性來刪除我的GridView的每一行,現在我想用存儲過程來刪除我的GridView的行,當我點擊「刪除」LinkButton。我在其他有關ASP.NET的論壇上嘗試了一些教程,但沒有任何反應使用存儲過程而不是使用SqlDataSource更新和刪除GridView中的行ASP.NET C#
謝謝
您可以使用item命令。在item命令中,您可以將要刪除的行的id作爲命令參數傳遞給您的刪除存儲過程,然後使用您選擇的存儲過程重新綁定gridview上的數據源。
<asp:LinkButton runat="server" OnCommand="Delete_Command" CommandName="Delete" CommandArgument='<%# Eval("DeleteRowID") %>'></asp:LinkButton>
VB.NET
Protected Sub Delete_Command(sender As Object, e As CommandEventArgs)
If e.CommandName.ToString = "Delete" Then
Dim DeleteRowId As String = e.CommandArgument.ToString
'call procedure here and pass argument delete row id
'ExambleGridView.DataSource= Call procedure here to get the datasource
ExambleGridView.DataBind()
End If
End Sub
C#
protected void Delete_Command(object sender, CommandEventArgs e)
{
if (e.CommandName.ToString == "Delete") {
string DeleteRowId = e.CommandArgument.ToString();
//Call Procedure here to delete row
ExampleGridview.Datasource=//Call Procedure here to get the datasource again
ExampleGridView.Databind()
}
}
看一看[本教程(http://www.ezzylearning.com/tutorial/editing-data-using -Asp淨gridview的控制)。它涵蓋了GridView編輯和更新的所有基礎知識。 – VDWWD
謝謝你的信息,我做到了。 –
當我點擊「編輯」按鈕來更改我的產品的「圖像」時,我試圖爲每行創建一個DropDownList。我做了一個函數來獲取所有的圖像url,但是當我設置DropDownList的數據源時,我得到錯誤。對不起,如果這個評論做錯了。 –