0
我有與ObjectDataSource控件DataList控件之前調用,問題是,當我調用Update方法,數據列表的selectmethod的更新方法,它在結果犯規顯示了更新的數據列表之前執行,我必須F5查看更新的結果,下面是代碼:的ObjectDataSource的Select方法更新按鈕
AspView
<asp:DataList ID="CustomersDefaultPaging" runat="server" Width="100%"
RepeatColumns="1" EnableViewState="False"
DataSourceID="CustomersDefaultPagingDataSource" DataKeyField="Id">
<ItemTemplate>.....</ItemTemplate>
<asp:ObjectDataSource ID="CustomersDefaultPagingDataSource" runat="server"
OldValuesParameterFormatString="original_{0}" SelectMethod="GetCustomersAsPagedDataSource"
TypeName="mobilecustomers"
OnSelected="CustomersDefaultPagingDataSource_Selected">
代碼隱藏
protected void CustomersDefaultPagingDataSource_Selected(object sender, ObjectDataSourceStatusEventArgs e)
{
// Reference the PagedDataSource bound to the DataList
PagedDataSource pagedData = (PagedDataSource)e.ReturnValue;
// Remember the total number of records being paged through across postbacks
TotalRowCount = pagedData.DataSourceCount;
// Configure the paging interface based on the data in the PagedDataSource
FirstPage.Enabled = !pagedData.IsFirstPage;
PrevPage.Enabled = !pagedData.IsFirstPage;
NextPage.Enabled = !pagedData.IsLastPage;
LastPage.Enabled = !pagedData.IsLastPage;
// Display the current page being viewed...
CurrentPageNumber.Text = string.Format("You are viewing page {0} of {1}...", PageIndex + 1, PageCount);
}
protected void btnSave_Click(object sender, EventArgs e)
{
foreach (DataListItem item in CustomersDefaultPaging.Items)
{
customers.UpdateCustomerAddress(.........);
}
}
DataAcess
static public DataTable GetAllCustomers()
{
string sql = "Select * from [Customers] where [Upgrade] = 0";
SqlDataAdapter da = new SqlDataAdapter(sql, ConnectionString);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
public PagedDataSource GetCustomersAsPagedDataSource(string sortExpression, int pageIndex, int pageSize)
{
DataTable dt = new DataTable();
dt = GetAllCustomers();
dt.DefaultView.Sort = sortExpression;
// Limit the results through a PagedDataSource
PagedDataSource pagedData = new PagedDataSource();
pagedData.DataSource = dt.DefaultView;
//pagedData.DataBind();
pagedData.AllowPaging = true;
pagedData.CurrentPageIndex = pageIndex;
pagedData.PageSize = pageSize;
return pagedData;
}
上更新單擊DataList控件應該只顯示客戶,其升級值爲0,Curretly當我更新字段爲0,它更新SQL數據庫,但它在DataList我必須刷新它以犯規節目查看更新。