Skip to main content

Detail table delete selected record

Detail When the DELETE button, which is the feature of the table, is used to delete the records added to the table, it starts to delete from the last record. The following code example can be used to delete the selected row.

Details Code to copy the table to a datatable and delete it according to the checkbox object in it

DataTable dt = new DataTable("Seda");

Create Datatable Columns According to Your Own Columns

Dt. Columns.Add("lst_tbl_PlantCode",typeof(String));

Dt. Columns.Add("txt_tbl_BoxPlant",typeof(String));

Dt. Columns.Add("txt_ReqCreditLimit",typeof(String));

Dt. Columns.Add("lst_PaymentTerm",typeof(String));

Dt. Columns.Add("lst_PaymentMethod",typeof(String));

Dt. Columns.Add("txt_Rebates",typeof(String));

if(DetailsGrid1.CurrentRowCount > 0)

{

int = count

for(int a = 0 ; a < DetailsGrid1.CurrentRowCount; a++ )

{

bool text = ((CheckBox)DetailsGrid1.GetRowObject(a,"CheckBoxControlDG")). Checked;

if(text)

{

Details1.DeleteRow(a);

Table1.DeleteRow(a);

a--;

}else{

DataRow = dt. NewRow();

drow["lst_tbl_PlantCode"] = ((eBAComboBox)DetailsGrid1.GetRowObject(a,"lst_tbl_PlantCode")). Text;

drow["txt_tbl_BoxPlant"] = ((TextBox)DetailsGrid1.GetRowObject(a,"txt_tbl_BoxPlant")). Text;

drow["txt_ReqCreditLimit"] = ((TextBox)DetailsGrid1.GetRowObject(a,"txt_ReqCreditLimit")). Text;

drow["lst_PaymentTerm"] = ((DropDownList)DetailsGrid1.GetRowObject(a,"lst_PaymentTerm")). SelectedValue.ToString();

drow["lst_PaymentMethod"] = ((DropDownList)DetailsGrid1.GetRowObject(a,"lst_PaymentMethod")). SelectedValue.ToString();

drow["txt_Rebates"] = ((TextBox)DetailsGrid1.GetRowObject(a,"txt_Rebates")). Text;

Dt. Rows.Add(drow);

}

}

}

SaveFormData(false,true);

DetailsGrid1.CurrentRowCount = 0;

foreach(DataRow drow in dt. Rows){

DetailsGrid1.CurrentRowCount++;

((CheckBox)DetailsGrid1.GetRowObject(DetailsGrid1.CurrentRowCount-1,"CheckBoxControlDG")). Checked = false;

((eBAComboBox)DetailsGrid1.GetRowObject(DetailsGrid1.CurrentRowCount-1,"lst_tbl_PlantCode")). Text = drow["lst_tbl_PlantCode"]. ToString();

((TextBox)DetailsGrid1.GetRowObject(DetailsGrid1.CurrentRowCount-1,"txt_tbl_BoxPlant")). Text = drow["txt_tbl_BoxPlant"]. ToString();

((TextBox)DetailsGrid1.GetRowObject(DetailsGrid1.CurrentRowCount-1,"txt_ReqCreditLimit")). Text = drow["txt_ReqCreditLimit"]. ToString();

((DropDownList)DetailsGrid1.GetRowObject(DetailsGrid1.CurrentRowCount-1,"lst_PaymentTerm")). SelectedValue= drow["lst_PaymentTerm"]. ToString();

((DropDownList)DetailsGrid1.GetRowObject(DetailsGrid1.CurrentRowCount-1,"lst_PaymentMethod")). SelectedValue = drow["lst_PaymentMethod"]. ToString();

((TextBox)DetailsGrid1.GetRowObject(DetailsGrid1.CurrentRowCount-1,"txt_Rebates")). Text= drow["txt_Rebates"]. ToString();

}