RadGrid is Clearing Rws after Item_Cmmand Event Post

2 posts, 1 answers
  1. Jaish
    Jaish avatar
    12 posts
    Member since:
    Mar 2015

    Posted 10 Aug 2015 Link to this post

    Below is my Rad grid which is binding from sever side during Page_Load. But once I clicked the "Edit" command, all rows are seeing as cleared after that post back. My edit command is not inline, but it's showing the results on a separate page section. If I replace this grid with normal asp.net GridView, the rows are retaining for the same operation. This RadGrid is inside a usercontrols(ascx) and this usercontrol is inside a RadAjaxPanel of the container page. It appears like ViewState is not ​retaining for me once using RadGrid. Any suggestions?

    <P><telerik:RadGrid runat="server" ID="grdItemEnquiry" Width="95%"
    CssClass="gridview1" ShowFooter="false" AllowSorting="true" AllowPaging="true"
    PageSize="20" EnableViewState="true" Visible="true"
    OnItemDeleted="grdItemEnquiry_OnRowDeleting"
    OnItemCommand="grdItemEnquiry_RowCommand"AutoGenerateColumns="false"ShowHeaderWhenEmpty="true"RowStyle-CssClass="alterwhite"OnItemDataBound="grdItemEnquiry_OnRowDataBound"AlternatingRowStyle-CssClass="altergrey"
    HeaderStyle-CssClass="tableHeading br"
    OnPageIndexChanged="grdItemEnquiry_PageIndexChanging"><BR>                                                      
    <ClientSettingsAllowColumnsReorder="true"><BR>                                                             
    <ClientEventsOnCommand="rgPublicationResults_Command"/><BR>                                                      
    </ClientSettings><BR>                                                      
    <MasterTableView><BR>                                                             
    <Columns><BR>                                                                    
    <telerik:GridTemplateColumnHeaderText="S.No"ItemStyle-Width="3%"><BR>                                                                          
    <ItemTemplate><BR>                                                                                 
    <asp:Label ID="lblSRNO"runat="server"Text='<%#Container.ItemIndex +1
    %>'></asp:Label><BR>                                                                          
    </ItemTemplate><BR>                                                                    
    </telerik:GridTemplateColumn><BR>                                                                    
    <telerik:GridTemplateColumnHeaderText="SerialNo"Visible="false"><BR>                                                                          
    <ItemTemplate><BR>                                                                                 
    <asp:Label ID="lblSerialNo"runat="server"Text='<%#Eval("SerialNo")
    %>'></asp:Label><BR>                                                                                 
    <asp:Label ID="lblItemID"runat="server"Text='<%#Eval("ItemID")
    %>'></asp:Label><BR>                                                                          
    </ItemTemplate><BR>                                                                    
    </telerik:GridTemplateColumn><BR>                                                                    
    <telerik:GridTemplateColumnHeaderText="Item Description"
    ItemStyle-Width="10%"
    ItemStyle-CssClass="breakWord120"><BR>                                                                          
    <ItemTemplate><BR>                                                                                 
    <asp:Label ID="lblItemDescr"runat="server"Text='<%#Eval("ItemDesc")
    %>'></asp:Label><BR>                                                                          
    </ItemTemplate><BR>                                                                    
    </telerik:GridTemplateColumn><BR>                                                                    
    <telerik:GridTemplateColumnHeaderText="Item Code" ItemStyle-Width="5%"
    ItemStyle-CssClass="breakWord120"><BR>                                                                          
    <ItemTemplate><BR>                                                                                 
    <asp:Label ID="lblItemCode"runat="server"Text='<%#Eval("ItemCode")
    %>'></asp:Label><BR>                                                                          
    </ItemTemplate><BR>                                                                    
    </telerik:GridTemplateColumn><BR>                                                                    
    <telerik:GridTemplateColumnHeaderText="Delivery Location"
    ItemStyle-Width="7%"
    ItemStyle-CssClass="breakWord120"><BR>                                                                          
    <ItemTemplate><BR>                                                                                 
    <asp:Label ID="lblDelLoc"runat="server"Text='<%#Eval("DelLoc")
    %>'></asp:Label><BR>                                                                          
    </ItemTemplate><BR>                                                                    
    </telerik:GridTemplateColumn><BR>                                                                    
    <telerik:GridTemplateColumnHeaderText="Major Category" ItemStyle-Width="5%"
    ItemStyle-Wrap="true" ItemStyle-CssClass="DisplayNone"
    HeaderStyle-CssClass="DisplayNone"><BR>                                                                          
    <ItemTemplate><BR>                                                                                 
    <asp:DropDownList
    runat="server"ID="ddlcategory"Width="70px"BackColor="Cornsilk"AutoPostBack="true"OnSelectedIndexChanged="ddlcategory_SelectedIndexChanged"/><BR>                                                                          
    </ItemTemplate><BR>                                                                    
    </telerik:GridTemplateColumn><BR>                                                                    
    <telerik:GridTemplateColumnHeaderText="Minor Category" ItemStyle-Width="5%"
    ItemStyle-Wrap="true" ItemStyle-CssClass="DisplayNone"
    HeaderStyle-CssClass="DisplayNone"><BR>                                                                          
    <ItemTemplate><BR>                                                                                 
    <asp:DropDownList
    runat="server"ID="ddlsubcategory"Width="70px"BackColor="Cornsilk"OnSelectedIndexChanged="ddlsubcategory_SelectedIndexChanged"AutoPostBack="true"/><BR>                                                                          
    </ItemTemplate><BR>                          
                                              
    </telerik:GridTemplateColumn><BR>                                                                    
    <telerik:GridTemplateColumnHeaderText="UOM"ItemStyle-Width="4%"ItemStyle-Wrap="true"><BR>                                                                          
    <ItemTemplate><BR>                                                                                 
    <asp:Label ID="lblUOM" runat="server"Text='<%#Eval("UOM")
    %>'></asp:Label><BR>                                                                          
    </ItemTemplate><BR>                                                                    
    </telerik:GridTemplateColumn><BR>                                                                    
    <telerik:GridTemplateColumnHeaderText="Need By Date" ItemStyle-Width="5%"
    ItemStyle-Wrap="true"><BR>                                                                          
    <ItemTemplate><BR>                                                                                 
    <asp:Label ID="lblNeedDate"runat="server"Text='<%#Eval("NeedDate")
    %>'></asp:Label><BR>                                                                          
    </ItemTemplate><BR>                                                                    
    </telerik:GridTemplateColumn><BR>                                                                    
    <telerik:GridTemplateColumnHeaderText="Quantity/Duration"ItemStyle-Width="3%"ItemStyle-Wrap="true"ItemStyle-HorizontalAlign="Center"><BR>                                                                          
    <ItemTemplate><BR>                                                                                 
    <asp:Label
    ID="lblQuantity"runat="server"Text='<%#Eval("Quantity_Duration")
    %>'></asp:Label><BR>                                                                          
    </ItemTemplate><BR>                                                                          
    <FooterTemplate><BR>                                                                                 
    <asp:Label ID="lblGTotal"runat="server"Style="font-weight: bold"Text="Grand
    Total
     :"></asp:Label><BR>                                                                          
    </FooterTemplate><BR>                                                                    
    </telerik:GridTemplateColumn><BR>                                                                    
    <telerik:GridTemplateColumnHeaderText="Unit Price" ItemStyle-Width="3%"
    ItemStyle-HorizontalAlign="Right"><BR>                                                             
                   
    <ItemTemplate><BR>                                                                                 
    <asp:Label ID="lblprice"runat="server"Text='<%# String.Format("{0} {1}",
     Eval("Currency"), Eval("UnitPrice", "{0:0.000}"))
    %>'></asp:Label><BR>                                                                                 
    <asp:HiddenField
    ID="hdnUnitPrice"runat="server"Value='<%#Eval("UnitPrice") %>'
    /><BR>                                                                          
    </ItemTemplate><BR>                                                                    
    </telerik:GridTemplateColumn><BR>                                                                    
    <telerik:GridTemplateColumnHeaderText="Taxes"ItemStyle-Width="3%"ItemStyle-HorizontalAlign="Right"
    Visible="false"><BR>                                                                          
    <ItemTemplate><BR>                                                                                 
    <asp:Label
    ID="lblTaxes"runat="server"></asp:Label><BR>                                                                          
    </ItemTemplate><BR>                                                                    
    </telerik:GridTemplateColumn><BR>                                                                    
    <telerik:GridTemplateColumnHeaderText="Conversion Rate" ItemStyle-Width="3%"
    ItemStyle-HorizontalAlign="Center"><BR>                                                                          
    <ItemTemplate><BR>                                                                                 
    <asp:Label
    ID="lblConvRate"runat="server"></asp:Label><BR>                                                                                 
    <asp:Label ID="lbCurrencyValue"Style="display: none"
    runat="server"Text='<%#Eval("Currency")
    %>'></asp:Label><BR>                                                                          
    </ItemTemplate><BR>                                                                    
    </telerik:GridTemplateColumn><BR>                                                                    
    <telerik:GridTemplateColumnHeaderText="Total Price(QAR)" ItemStyle-Width="3%"
    ItemStyle-Wrap="true"
    ItemStyle-HorizontalAlign="Right"><BR>                                                                          
    <ItemTemplate><BR>                                                                                 
    <asp:Label ID="lblTotalPrice"Style="text-align: right; width: 70px"
    runat="server"ReadOnly="true"Text='<%#Eval("TotalPrice", "{0:#,#.000}")
    %>'></asp:Label><BR>                                                                          
    </ItemTemplate><BR>                                                                          
    <FooterTemplate><BR>                                                                          
           <telerik:RadNumericTextBox ID="lblTotal"
    Style="text-align: right" runat="server" CssClass="textEntry" ReadOnly="true"
    MaxLength="10"><BR>                                                                                        
    <NumberFormatDecimalDigits="3"/><BR>                                                                          
            
    </telerik:RadNumericTextBox><BR>                                                                          
    </FooterTemplate><BR>                                                                    
    </telerik:GridTemplateColumn><BR>                                                                    
    <telerik:GridTemplateColumnHeaderText="File Name" ItemStyle-Width="7%"
    ItemStyle-Wrap="true"
    ItemStyle-CssClass="breakWord120"><BR>                                                                          
    <ItemTemplate><BR>                                                                                 
    <asp:LinkButton
    ID="btnlineattach"OnClientClick="setFileDownLoadToken();"runat="server"ToolTip="View
     File" CommandName="ViewAttach" OnClick="btnviewattach_Click"
    Text='<%#Eval("DocTitle") %>' Style="color: #630040 !important;"
    Font-Underline="true" ForeColor="Blue"
    CommandArgument='<%#Eval("DocumentFilePath")%>'><BR>                                                                                        
    <asp:Label runat="server"ID="lblattachpath"Text='<%#Eval("DocTitle")
    %>'></asp:Label><BR>                                                                                 
    </asp:LinkButton><BR>                                                                          
    </ItemTemplate><BR>                                                                          
    <ItemStyleWidth="10%"/><BR>                                                                    
    </telerik:GridTemplateColumn><BR>                                                                    
    <telerik:GridBoundColumn
    DataField="VirtualPath"Visible="false"HeaderText="Description"/><BR>                                                                    
    <telerik:GridBoundColumn
    DataField="Type"Visible="false"HeaderText="Action"/><BR>                                                                    
    <telerik:GridTemplateColumnHeaderText="Is Urgent Requisition"
    ItemStyle-Width="8%" ItemStyle-Wrap="true" ItemStyle-HorizontalAlign="Center"
    Visible="false" ItemStyle-CssClass="hiddencol"
    HeaderStyle-CssClass="hiddencol"><BR>                                                                          
    <ItemTemplate><BR>                                                                                 
    <asp:Label ID="lblIsReqUrgent"runat="server"Text='<%#Eval("IsReqUrgent")
    %>'></asp:Label><BR>                                                                    
            
    </ItemTemplate><BR>                                                                    
    </telerik:GridTemplateColumn><BR>                                                                    
    <telerik:GridTemplateColumnHeaderText="Future Requirement"
    ItemStyle-Width="8%" ItemStyle-Wrap="true" ItemStyle-HorizontalAlign="Center"
    Visible="true"><BR>                                                                          
    <ItemTemplate><BR>                                                                                 
    <asp:Label
    ID="lblFutureRequirement"runat="server"Text='<%#Eval("FutureRequirement")
    %>'></asp:Label><BR>                                                                          
    </ItemTemplate><BR>                                                                    
    </telerik:GridTemplateColumn><BR>                                                                    
    <telerik:GridTemplateColumnItemStyle-Width="3%"HeaderText="Edit"><BR>                                                                          
    <ItemTemplate><BR>                                                                                 
    <asp:ImageButton
    ID="btnedit"runat="server"ImageUrl="~/Images/edit1.png"ToolTip="Edit"CommandName="Edit"CommandArgument='<%#Eval("SerialNo")
    %>'
    TabIndex="19"/><BR>                                                                          
    </ItemTemplate><BR>                                                                          
    <ItemStyleWidth="3%"HorizontalAlign="Center"></ItemStyle><BR>                                                                    
    </telerik:GridTemplateColumn><BR>                                                                    
    <telerik:GridTemplateColumnHeaderText="Delete"ItemStyle-Width="5%"><BR>                                                                          
    <ItemTemplate><BR>                                                                                 
    <asp:ImageButton
    ID="btnDelete"runat="server"ImageUrl="~/Images/delete.png"ToolTip="Delete"CommandName="Delete"CommandArgument='<%#Eval("ItemID")
    %>' OnClientClick="return confirm('Do you really want to delete?');"
    /><BR>                                                                          
    </ItemTemplate><BR>                                                                          
    <ItemStyleHorizontalAlign="Center"Width="5%"></ItemStyle><BR>                                                                    
    </telerik:GridTemplateColumn><BR>                                                             
    </Columns><BR>                                                      
    </MasterTableView><BR>                                               
    </telerik:RadGrid></P>

  2. Answer
    Eyup
    Admin
    Eyup avatar
    3699 posts

    Posted 13 Aug 2015 Link to this post

    Hello Jaish,

    The NeedDataSource event is the mandatory way when you need to bind the grid to a programmatic data source in the code-behind. It is important to note that you are not using DataBind() to bind the grid. Performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, Grouping, Exporting, Paging, Sorting, Filtering, etc. require accommodating appropriate database operations.  Therefore, we suggest you to avoid Simple Databinding and strongly recommend the use of more advanced databinding methods, which automatically handle the aforementioned functions:
    Declarative DataSource
    Programmatic Data Binding


    Please make the suggested modification and let me know about the result.


    Regards,
    Eyup
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top