Reputation: 29
I need you all help on pulling data from a table based on lot num, and then displayed it into grid view. Then for the grid view, there are check box on each records for user to check and click on the delete button. Once delete the record will be deleted. Can anyone of you show me any reference or example?
Seriously need help. Thanks.
Upvotes: 0
Views: 1093
Reputation: 29
if (e.Row.RowType == DataControlRowType.DataRow)
{
Button btnDelete = (Button)gvResult.Row.FindControl("btnDelete");
CheckBox chkBox = (CheckBox)gvResult.Row.FindControl("chkBox");
if (chkBox.Checked == true)
{
if (chkBox.Text != "")
{
int id = Convert.ToInt32(chkBox.Text);
//Pass this ID to DB and Delete record.
string SQL = string.Format(@"DELETE FROM RF_HANDLING WHERE LOTNUM = '{0}' AND PRICE = '{1}'", LotName, PRICE);
}
}
}
Upvotes: 0
Reputation: 63
refer GridView below example, Main things to see 1. OnRowDeletingEvent 2. Checkbox and button in ItemTemplate
<asp:GridView ID="GVID" AutoGenerateColumns="false" runat="server" **OnRowDeleting="GVID_RowDeleting"** >
<column>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:Checkbox ID="CHKID" runat="server" Text=**'<%#Eval("IDColumnName") %>'** />
<asp:Button ID="btnDelete" runat="server" **CommandName="Delete"** />
</column>
C# code behind:
protected void GV_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Button btnDelete = (Button)e.Row.FindControl("btnDelete");
CheckBox CHKID= (CheckBox)e.Row.FindControl("CHKID");
if(CHKID.Checked == true)
{
if(CHKID.Text !="")
{
int id = Convert.ToInt32(CHKID.Text);
//Pass this ID to DB and Delete record.
}
}
}
}
Upvotes: 0