For this purpose, you first set the primary key identifier in your table, which you retrieve as the grid source.
After you snap the grid, you must save this identifier in a hidden field. see the following code:
<asp:GridView ID="gvwID" runat="server" AutoGenerateColumns="False" DataKeyNames="TableID"> <Columns> <asp:TemplateField> <asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Eval("TableID") %>'/> <asp:TemplateField> </Columns> </asp:GridView>
Then, in the delete window, click the "Delete" button to get the selected row identifiers:
protected void Btn_Click(object sender, EventArgs e) { int[] OrderIDList = new int[gvwID.Rows.Count]; int index = 0; for (int count = 0; count < gvwID.Rows.Count; count++) { if (gvwID.Rows[count].FindControl("chkSelect") != null) { if (((CheckBox)gvwID.Rows[count].FindControl("chkSelect")).Checked) { if (gvwID.Rows[count].FindControl("HiddenField1") != null) { string OrderID = ((HiddenField)gvwID.Rows[count].FindControl("HiddenField1")).Value; OrderIDList[index++] = Convret.ToInt32(OrderID); } } } }
Then create the added row from the OrderIDList and pass it to the stored procedure. create xml from the stored procedure using the added string. Skip through xml and get each id and do the uninstall.
see procedure below:
@IDList varchar(MAX) DECLARE @xmlUserIDs xml SELECT @xmlUserIDs = CONVERT(xml,'<root><cat>' + REPLACE(@IDList,',','</cat><cat>') + '</cat></root>')// creates xml from appended string DELETE FROM [TableName] WHERE [TableID] IN (SELECT [Value] = TCvalue('.','int') FROM @xmlUserIDs.nodes('/root/cat') T(C));
Hope this helps you.
source share