I have a CommandArgument that takes in 1 argument from a LinkButton in my GridVie for row deletion in GridView.
Code in my aspx.cs:
LinkButton lnk = (LinkButton)sender;
string stid = lnk.CommandArgument.ToString();
SqlConnection conn = new SqlConnection("<Connection>");
string sql = string.Format("DELETE FROM [ConflictingRole] where Role like '%{0}%'",stid);
SqlCommand cmd = new SqlCommand(sql, conn);
conn.Open();
cmd.ExecuteNonQuery();
Code in my .aspx:
<asp:GridView ID="GridView1" ondatabound="gv_DataBound" runat="server" DataSourceID="SqlDataSource1">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="UserSelection" OnCheckedChanged="CRUserSelector_CheckedChanged" ondatabound="gv_DataBound" runat="server" />
<asp:LinkButton ID="lnkDelete" runat="server" onclick="lnkDelete_Click" Text="Delete" CommandArgument='<%# Eval("Role") %>' PostBackUrl="~/CRList.aspx" ></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
My current CommandArgument only takes in one column name, which is Role. However, I would like to take in 2 column names, and use the 2 column names in my String sql statement in aspx.cs.
Reason: I have multiple rows with the same value of “Row”, thus if I delete based on the “Role” column’s value, I will delete multiple rows. I would want to take in values from both “Role” and “ConflictingRole” for the delete sql query.
May I know if it is possible to do so?
Thank You.
You may pass value of two or more columns by converting them to string with comma delimiter.
split the commandArgument value in the handler,
EDIT:
You may write delete query like:
OR
Or Hard coded sql statement (which is not recommend)