tags:

views:

908

answers:

1

I have a DataList that is bound to a SQlDataSource. The SQLDataSource returns a stored procedure value containing the max indentity value in a table.

On the same page as the DataList I have a DetailsView that is used to add new records to the table.

The problem is that after adding a new record to the table the Datalist value shows the previous indentity value.

How do I have the page automatically refresh the DataList?

+3  A: 

Call DataList.DataBind() in either the page load method or the ItemInserted method of the Details View.

For example:

void YourDetailsView_ItemInserted(object sender, 
DetailsViewInsertedEventArgs e)
{
    // Refresh the DataList control after a new record is inserted 
    // in the DetailsView control.
    YourDataList.DataBind();
}

And in the markup:

<asp:DetailsView id="YourDetailsView" runat="server" 
DataSourceID="YourSQLDataSourceID" OnItemInserted="YourDetailsView_ItemInserted"/>
Matthew Jones
The Datalist still won't refresh after trying both your suggestions. The list will refresh when changing to a different page though in the detailsview.
John M
Are these two elements in different UpdatePanels? You might need to set a trigger on the UpdatePanel containing the list to fire when the DetailsView inserts an item.
Matthew Jones
I am not using any UpdatePanels. The Datalist and DetailsView are bound to two different data sources though (same base table).Does the Paging option on the DetailsView cause an event to fire?
John M
Figured it out - forgot to assign the ItemInserted code to the ItemInserted event of the DetailsView.Thanks Matthew.
John M