Delete rows from Detail Table
In detail table object properties, the delete button deletes only the last row. However, deregistration can be performed by different methods.
In order for this process to take place when the delete button is clicked; Operation must be provided on the RowDeleting event of the detail table. When the delete button is clicked, the command (args.allow = false;) must be used to cancel the default deletion.
In order to delete a record, a selection object (checkbox) will be required on the detail table first. The selected ones can be transferred to the datatable and the same detail table can be filled with this datatable again.
using System.Web.UI.WebControls;
public void DetailsGrid3_RowDeleting(object sender, DetailsGridDeleteRowEventArgs args)
{
args.allow = false;
DataTable dt = new DataTable();
Dt. Columns.Add("List1");
Dt. Columns.Add("List1_Value");
Dt. columns.add("list2");
Dt. Columns.Add("List2_Value");
Dt. columns.add("text4");
for (int i = 0; i ```<``` DetailsGrid3.CurrentRowCount; i++)
{
if (!( (CheckBox)DetailsGrid3.GetRowObject(i, "CheckBox3")). Checked)
{
DataRow dr = dt. NewRow();
dr["List1"] = ((DropDownList)DetailsGrid3.GetRowObject(i, "List1")). SelectedItem.Text;
dr["List1_Value"] = ((DropDownList)DetailsGrid3.GetRowObject(i, "List1")). SelectedItem.Value;
dr["List2"] = ((eBAComboBox)DetailsGrid3.GetRowObject(i, "List2")). Text;
dr["List2_Value"] = ((eBAComboBox)DetailsGrid3.GetRowObject(i, "List2")). Value;
dr["Text4"] = ((TextBox)DetailsGrid3.GetRowObject(i, "Text4")). Text;
Dt. Rows.Add(dr);
}
}
DetailsGrid3.CurrentRowCount = 0;
for (int y = 0; y ```<``` dt. Rows.Count; y++)
{
DetailsGrid3.CurrentRowCount++;
((DropDownList)DetailsGrid3.GetRowObject(y, "List1")). SelectedItem.Text = dt. rows[y]["list1"]. ToString();
((DropDownList)DetailsGrid3.GetRowObject(y, "List1")). SelectedItem.Value = dt. Rows[y]["List1_Value"]. ToString();
((eBAComboBox)DetailsGrid3.GetRowObject(y, "List2")). Text = dt. rows[y]["list2"]. ToString();
((eBAComboBox)DetailsGrid3.GetRowObject(y, "List2")). Value = dt. Rows[y]["List2_Value"]. ToString();
((TextBox)DetailsGrid3.GetRowObject(y, "Text4")). Text = dt. rows[y]["text4"]. ToString();
((CheckBox)DetailsGrid3.GetRowObject(y, "CheckBox3")). Checked = false;
}
}
NOTE: As of version 6.7.153, when deleting rows in the detail table, when accessing the eBADropDownList object in the detail table,
((DropDownList) dtg1. GetRowObject(i, "List1")). SelectedItem.Value
((DropDownList) dtg1. GetRowObject(i, "List1")). SelectedItem.Text
Instead of its use,
((DropDownList) dtg1. GetRowObject(i, "List1")). SelectedValue
Structure should be used. In this case, the _TEXT value of the eBADropDownList should also be kept It will not remain.