This is a migrated thread and some comments may be shown as answers.

Grid items are being lost between posts

3 Answers 30 Views
Grid
This is a migrated thread and some comments may be shown as answers.
DaveBarkshire
Top achievements
Rank 1
DaveBarkshire asked on 09 Jul 2012, 11:02 AM
I have a radGrid and am trying to get the ItemCommand buttons working. When the item command button is clicked the ItemCommand event filres and I can see here that the grid has 4 items (rgdGrid.Items.Count = 4). But when the page pre render event fires the items have been lost (rgdGrid.Items.Count = 0).

I bind data programatically then the grid is first shown and do not need to do it again. Viewstate is enabled for this grid control.

Any ideas?
------------------------------------------

protected

 

void rgdGrid_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)

 

protected

 

override void OnPreRender(EventArgs e)
------------------------------------------

 

<

 

telerik:RadGrid ID="rgdGrid" runat="server" AutoGenerateColumns="False" Culture="en-GB"

 

 

 

 

 

ShowStatusBar="True" ShowFooter="False" OnUpdateCommand="rgdGrid_UpdateCommand"

 

 

 

 

 

OnEditCommand="rgdGrid_EditCommand"

 

 

OnItemDataBound="rgdGrid_ItemDataBound" OnCancelCommand="rgdGrid_CancelCommand"

 

 

 

 

 

AllowSorting="True" GroupingEnabled="False" OnSortCommand="rgdGrid_SortCommand"

 

 

 

 

 

Width="100%" ShowGroupPanel="True" Skin="Web20" MasterTableView-CellPadding="0"

 

 

 

 

 

MasterTableView-CellSpacing="0" CellPadding="0"

 

 

onitemcommand="rgdGrid_ItemCommand">

 

 

 

 

 

<MasterTableView EnableHeaderContextMenu="true" EditMode="InPlace" ItemStyle-Wrap="False"

 

 

 

 

 

CommandItemDisplay="TopAndBottom" >

 

 

 

 

 

<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">

 

 

 

 

 

</RowIndicatorColumn>

 

 

 

 

 

<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">

 

 

 

 

 

</ExpandCollapseColumn>

 

 

 

 

 

<Columns>

 

-----------------------------------------------------

<

 

CommandItemTemplate>

 

 

<p style="text-align: right;">

 

 

<asp:LinkButton ID="btnEditSelected" runat="server" CommandName="EditAll" Visible="True"

 

 

Text="Edit" />

 

 

<asp:LinkButton ID="btnUpdate" runat="server" CommandName="UpdateAll" Visible="True"

 

 

Text="Update" />

 

 

</p>

 

 

</CommandItemTemplate>

 

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 10 Jul 2012, 06:45 AM
Hi,

Try getting the items count in OnPreRenderComplete.

C#:
protected override void OnPreRenderComplete(EventArgs e)
    int count = RadGrid1.Items.Count;
}

Thanks,
Shinu.
0
DaveBarkshire
Top achievements
Rank 1
answered on 10 Jul 2012, 10:37 AM
It is zero here too.

Also, using this event causes the grid javascript on the page to fail which is strange.

Anyway, it seems that the grid does not retain its state between posts so I have to re-populate from data every post.

At least I can capture the posted data in rgdGrid_ItemCommand which allows me to do what I need to do.
0
Shinu
Top achievements
Rank 2
answered on 11 Jul 2012, 10:31 AM
Hello,

Unfortunately I cannot replicate the issue at my end. Here is the sample code that I tried which worked as expected.
aspx:
<telerik:RadGrid ID="grid" runat="server" AllowFilteringByColumn="true"  AllowPaging="true" PageSize="4" AutoGenerateColumns="false" onitemdatabound="p_ItemDataBound" onneeddatasource="grid_NeedDataSource">
 <telerik:GridBoundColumn UniqueName="EmployeeID" DataField="EmployeeID"  HeaderText="EmployeeID"></telerik:GridBoundColumn>
 <telerik:GridBoundColumn UniqueName="LastName" DataField="LastName"  HeaderText="LastName"></telerik:GridBoundColumn>
 <telerik:GridBoundColumn UniqueName="FirstName" DataField="FirstName"  HeaderText="FirstName"></telerik:GridBoundColumn>
</telerik:RadGrid>
C#:
protected void grid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
  SqlConnection con1 = new SqlConnection(WebConfigurationManager.ConnectionStrings["NorthwindConnectionString3"].ConnectionString);
  SqlCommand cmd = new SqlCommand("SELECT * FROM [Employees]", con1);
  SqlDataAdapter ad = new SqlDataAdapter(cmd);
  DataSet ds = new DataSet();
  ad.Fill(ds);
  grid.DataSource = ds;
}
protected override void OnPreRenderComplete(EventArgs e)
{
  int count = grid.Items.Count;
}

Thanks,
Shinu.
Tags
Grid
Asked by
DaveBarkshire
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
DaveBarkshire
Top achievements
Rank 1
Share this question
or