Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For this purpose you have set a primary key id first in your table, which you are fetching as a source of the Grid.</p> <p>After binding the grid you should save that id in a hidden field. see the code below:</p> <pre><code> &lt;asp:GridView ID="gvwID" runat="server" AutoGenerateColumns="False" DataKeyNames="TableID"&gt; &lt;Columns&gt; &lt;asp:TemplateField&gt; &lt;asp:HiddenField ID="HiddenField1" runat="server" Value='&lt;%# Eval("TableID") %&gt;'/&gt; &lt;asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; </code></pre> <p>Then in the delete button click event get the selected row ids:</p> <pre><code> protected void Btn_Click(object sender, EventArgs e) { int[] OrderIDList = new int[gvwID.Rows.Count]; int index = 0; for (int count = 0; count &lt; 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); } } } } </code></pre> <p>Then create an appended string from OrderIDList and pass it to the stored procedure. from the stored procedure create an xml using the appended string. Loop through the xml and get each id and perform the deletion.</p> <p>see the procedure below:</p> <pre><code> @IDList varchar(MAX) DECLARE @xmlUserIDs xml SELECT @xmlUserIDs = CONVERT(xml,'&lt;root&gt;&lt;cat&gt;' + REPLACE(@IDList,',','&lt;/cat&gt;&lt;cat&gt;') + '&lt;/cat&gt;&lt;/root&gt;')// creates xml from appended string DELETE FROM [TableName] WHERE [TableID] IN (SELECT [Value] = T.C.value('.','int') FROM @xmlUserIDs.nodes('/root/cat') T(C)); </code></pre> <p>Hope this helps you.. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload