I have a datarepeater and the following code ONLY deletes the FIRST record regardless of which one is selected. I am not entirely convinced this is the correct way to do it with a datarepeater but I could not find a better solution. I need to be able to select any record and delete it.
//delete document
private void cmdDeleteDoc_Click(object sender, EventArgs e)
{
if (this.dataRepeater1.CurrentItemIndex == 0)
{
//begin reset
this.dataRepeater1.BeginResetItemTemplate();
// Delete Row Here
DataClasses1DataContext db = new DataClasses1DataContext();
System.Data.DataRowView SelectedRowView;
newCityCollectionDataSet.DocumentsRow SelectedRow;
SelectedRowView = (System.Data.DataRowView)documentsBindingSource.Current;
SelectedRow = (newCityCollectionDataSet.DocumentsRow)SelectedRowView.Row;
var matchedDocument = (from c开发者_JAVA百科 in db.GetTable<Document>()
where c.DocIDKey == SelectedRow.DocIDKey
select c).SingleOrDefault();
db.Documents.DeleteOnSubmit(matchedDocument);
db.SubmitChanges();
LoadCaseNumberKey(matchedDocument.CaseNumberKey, false, "documents");
this.dataRepeater1.EndResetItemTemplate();
}
}
Any help would be great!.
My guess is that your are mixed up between your documentsBindingSource and your dataRepeater.
What you "see" visually is the dataRepeater, while what you "get", is the documentsBindingSource.Current (that you retrieve as being SelectedRowView)
which is always set to 0 index. This is an all-too-common Winforms control trap.
加载中,请稍侯......
精彩评论