Hi, I have one telerik rad grid.Using a method i am filling the grid.I have enabled paging property.I have used itemtemplate-->ImageButton for delete and edit options.I have set page size as 10.Page load time it is working properly and populating the grid.After inserting 11 th row the pagination starts and it will show in next page with one record.But when i am deleting the 11th row the grid become blank.I have used dataset to bind the records. radgrid.DataBind(); dsDataset.Dispose();. But its item.count is 0. What is the reason?
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
PopulatePackage();
}
}
catch (Exception ex)
{
lblMessage.Text = objUtl.GetErrorMessage(ex, this);
lblMessage.Visible = true;
protected void gvPackage_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
try
{
SqlHelper objSQL = new SqlHelper();
DataSet dsPackage = new DataSet();
dsPackage = objSQL.ExecuteDataset("AL_PackageType_List_Retrieve",
objUtl.NumericEntry(Session["LocationId"].ToString()));
gvPackage.DataSource = dsPackage.Tables[0];
dsPackage.Dispose();
//PopulatePackage();
}
catch (Exception ex)
{
lblMessage.Text = objUtl.GetErrorMessage(ex, this);
lblMessage.Visible = true;
}
}
private void PopulatePackage()
{
try
{
lblMessage.Text = string.Empty;
SqlHelper objSQL = new SqlHelper();
DataSet dsPackage = new DataSet();
dsPackage = objSQL.ExecuteDataset("AL_PackageType_List_Retrieve",
objUtl.NumericEntry(Session["LocationId"].ToString()));
gvPackage.DataSource = null;
gvPackage.DataSource = dsPackage.Tables[0];
gvPackage.DataBind();
//dsPackage.Dispose();
if (gvPackage.Items.Count <= 0)
{
lblMessage.Text = "No Package Details Found...";
gvPackage.Visible = false;
}
else
{
gvPackage.Visible = true;
}
}
catch (Exception ex)
{
lblMessage.Text = objUtl.GetErrorMessage(ex, this);
lblMessage.Visible = true;
}
}
I have a RadListBox showing selected filter rules. I can add items to this ListBox by transferring from other ListBoxes or by creating from other controls' data using client-side javascript. When I add or remove items, I update RadGrid asynchronously using RadAjaxManager. In javascript always when I add or remove items to the ListBox, I call a function to make RadAjaxManager to update RadGrid.
When I add new items, the items appear in the ListBox client-side and also server-side. But when I remove items, it removes the item client-side and calls the AjaxManager request, but the items are not removed from the server side collection. For example if I add and remove the exactly same item 5 times, then I would have 0 items shown in the client-side ListBox but the same item 5 times in the server-side collection.
I am using trackChanges() and commitChanges() functions both when adding or deleting items. The ListBox is not posted back. Why is it so that adding items using these functions works but removing doesn’t?
Thanks,
Simo
Here are the functions to add and delete the items and call the Ajax manager (alerts for testing purposes):
function
StateListBoxItemDblClicked() {
alert(
"StateListBoxItemDblClicked "
+ ListboxDestination.get_items().get_count());
var
listBoxSource = $find(
"<%= UseCaseStateRadListBox.ClientID %>"
);
listboxDestination.trackChanges();
var
item = listBoxSource.get_selectedItem();
listBoxSource.transferToDestination(item);
listboxDestination.commitChanges();
UseCaseRadGridRebind();
}
function
DeleteSelectedItemFromDestination() {
listboxDestination.trackChanges();
var
item = listboxDestination.get_selectedItem();
listboxDestination.get_items().remove(item);
listboxDestination.commitChanges();
alert(
"Deleted "
+ listboxDestination.get_items().get_count());
UseCaseRadGridRebind();
}
function
UseCaseRadGridRebind() {
$find(
"<%= RadAjaxManager1.ClientID %>"
).ajaxRequest(
"UseCaseRadGridRebind"
);
}
Here is the RadAjaxManager, RadGrid inside RadPane and RadListBox inside RadPanelBar.
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
onajaxrequest
=
"RadAjaxManager1_AjaxRequest"
EnableViewState
=
"False"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadAjaxManager1"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"UseCaseRadGrid"
LoadingPanelID
=
"LoadingPanel1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
<
telerik:RadPane
runat
=
"server"
>
<
telerik:RadAjaxLoadingPanel
ID
=
"LoadingPanel1"
runat
=
"server"
Skin
=
"Default"
>
</
telerik:RadAjaxLoadingPanel
>
<
telerik:RadGrid
ID
=
"UseCaseRadGrid"
runat
=
"server"
AutoGenerateColumns
=
"False"
GridLines
=
"None"
Width
=
"440"
Visible
=
"true"
onselectedindexchanged
=
"UseCaseRadGrid_SelectedIndexChanged"
onitemcommand
=
"UseCaseRadGrid_ItemCommand"
onneeddatasource
=
"UseCaseRadGrid_NeedDataSource"
>
<
ClientSettings
EnablePostBackOnRowClick
=
"true"
>
<
Selecting
AllowRowSelect
=
"true"
/>
</
ClientSettings
>
<
MasterTableView
AutoGenerateColumns
=
"False"
ShowHeadersWhenNoRecords
=
"True"
EnableNoRecordsTemplate
=
"true"
>
<
Columns
>
...
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
</
telerik:RadPane
>
<
telerik:RadPanelItem
Text
=
"Valitut hakuehdot"
>
<
ContentTemplate
>
<
telerik:RadListBox
runat
=
"server"
ID
=
"RadListBoxDestination"
AutoPostBackOnDelete
=
"false"
Height
=
"200px"
Width
=
"500px"
AllowAutomaticUpdates
=
"false"
OnClientDeleted
=
"DeleteSelectedItemFromDestination"
AllowDelete
=
"True"
SelectionMode
=
"Multiple"
AllowReorder
=
"False"
OnClientItemDoubleClicked
=
"DeleteSelectedItemFromDestination"
/>
</
ContentTemplate
>
</
telerik:RadPanelItem
>
</
Items
>
</
telerik:RadPanelBar
>
protected
void
RadAjaxManager1_AjaxRequest(
object
sender, AjaxRequestEventArgs e)
{
if
(e.Argument ==
"UseCaseRadGridRebind"
)
UseCaseRadGrid.Rebind();
}
RadListBoxItemCollection RadListBoxDestinationItems = RadListBoxDestination.Items;