I have the following RowSourceNeeded handler :
However, I want the objects to be bound instead of just filling in cells so that something like this would work :
How can I acheive this?
void gvEmployes_RowSourceNeeded(object sender, GridViewRowSourceNeededEventArgs e){ if (e.Template == gvtEmployeLogiciels) { using ( var repo = new EmployesRepository()) { foreach (LogicielDTO l in repo.GetLogicielsOfEmploye((EmployeDTO)e.ParentRow.DataBoundItem)) { GridViewRowInfo gridRow = e.Template.Rows.NewRow(); gridRow.Cells["nom"].Value = l.nom; gridRow.Cells["nbLicense"].Value = l.nbLicense; e.SourceCollection.Add(gridRow); } } }}However, I want the objects to be bound instead of just filling in cells so that something like this would work :
void gvEmployes_UserDeletingRow(object sender, GridViewRowCancelEventArgs e){ foreach (var row in e.Rows) { switch (row.DataBoundItem.GetType().Name) // This will error if you are deleting a LogicielDTO row.
{ case "EmployeDTO": MessageBox.Show("Deleteing " + ((EmployeDTO)row.DataBoundItem).nom); break; case "LogicielDTO": MessageBox.Show("Deleteing " + ((LogicielDTO)row.DataBoundItem).nom); break; } }}How can I acheive this?