0

I have a record on detailsview. which gets data from onDataBound

<aasp:DetailsView ID="DetailsView1" runat="server" AllowPaging="False" 
    AutoGenerateRows="False" DataKeyNames="myID" DataSourceID="mySource"
    OnDataBound = "OnDetailsView_DataBound" >

and this is my OnDetailsView_DataBound

protected void OnDetailsView_DataBound(Object sender,EventArgs e)
    {
        if (DetailsView1.CurrentMode == DetailsViewMode.Edit)
        {
              //Display data in detailsview
        }
    }

It also has a delete button, which deletes the record. Before I didn't have the method "OnDetailsView_DataBound". So when I deleted a record, it just showed me a blank page. But now when I perform a delete, I get this error

Object reference not set to an instance of an object.

However, the data is deleted. I tried to check if the detailsview is empty by doing

if (Detailsview1.DataItemCount == 0)

but no luck. How do I handle empty data on delete in detailsview?

4

1 に答える 1

2

I figured this out myself. Here's a solution to my problem for others with same problem

DataRowView myView = (DataRowView)DetailsView1.DataItem;
        if (myView == null)
        {
于 2013-02-07T18:06:59.297 に答える