Batch edit mode Radgrid GridDateTimeColumn how to get selected value for date

8 posts, 0 answers
  1. vidya
    vidya avatar
    1 posts
    Member since:
    Jan 2015

    Posted 08 Jan 2015 Link to this post

    I have a radgrid in batch edit mode. I have GridDateTimeColumn. How can i get the selected value for the raddatepicker control in batch edit mode. I would like to do this on code behind. 

    I have copied radgrid control and radgrid's itemdatabound event below.

    But here is the part of the code behind code snippet with my problem.
    Inside the Itemdatabound event, i have this code to find the datepicker control.

     drVal("Expected_Date") is always dbnull. Why? 

    If drVal IsNot Nothing Then
    Dim dtExpected As RadDatePicker = DirectCast(editedItem("Expected_Date").Controls(0), RadDatePicker)
                    If drVal("Expected_Date") IsNot Nothing Then
                        If Not String.IsNullOrEmpty(drVal("Expected_Date").ToString) Then
                            dtExpected.SelectedDate = drVal("Expected_Date")
                        End If
                    End If
     End If

    aspx page
    ========
    <telerik:RadGrid ID="rgCriticalCaps" runat="server" CssClass="SubGridGeneral"  Width="100%"
        BorderStyle="Solid" BorderWidth="0px"  AllowAutomaticUpdates="True"
        AutoGenerateColumns="False" AllowPaging="false"
        AllowMultiRowEdit="True">
        <ClientSettings>
            <ClientEvents OnBatchEditOpening="BatchEditOpening" />
        </ClientSettings>
        <MasterTableView EditMode="Batch" DataKeyNames="PK_OrgSubmission, CapabilityID">
            <BatchEditingSettings EditType="Cell" />
            <NoRecordsTemplate>
                Test message
            </NoRecordsTemplate>
    <Columns>
                     
                <telerik:GridDropDownColumn UniqueName="Reason"
                    HeaderText="Reasons Not Met."
                      DropDownControlType="RadComboBox" AllowSorting="false" HeaderStyle-VerticalAlign="Top">
                </telerik:GridDropDownColumn>


                <telerik:GridDateTimeColumn DataField="Expected_Date" PickerType="DatePicker" 
                DataFormatString="{0:MM/dd/yyyy}" DataType="System.DateTime" HeaderText="Expected Date." 
                HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="13%" ItemStyle-HorizontalAlign="Left" UniqueName="Expected_Date" />

    </Columns>
                    
            <EditFormSettings>
                <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                </EditColumn>
            </EditFormSettings>
        </MasterTableView>
        <HeaderStyle CssClass="SubGridHeader" />
        <ItemStyle CssClass="SubGridRows" />
        <AlternatingItemStyle CssClass="SubGridAltRows" />
        <FilterMenu EnableImageSprites="False">
        </FilterMenu>
        <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
        </HeaderContextMenu>
    </telerik:RadGrid>

    Code behind
    ==========
    Protected Sub rgCriticalCaps_ItemDataBound(sender As Object, e As GridItemEventArgs) Handles rgCriticalCaps.ItemDataBound
                If e.Item.ItemType = GridItemType.EditItem And e.Item.IsInEditMode Then

                Dim editedItem As GridEditableItem = TryCast(e.Item, GridEditableItem)
                Dim editMan As GridEditManager = editedItem.EditManager

                Dim editor As GridDropDownListColumnEditor = TryCast(editMan.GetColumnEditor("Reason"), GridDropDownListColumnEditor)

                Dim SqlBuilder As StringBuilder = New StringBuilder
                SqlBuilder.Append("SELECT PK_PickList,DisplayValue FROM PickLists WHERE PK_PickListType IN (SELECT PK_PickListType FROM PickListTypes WHERE UsageField = 'Capabilities_Reason_NotMet')  order by SortPos")

                Dim gridSql As String = SqlBuilder.ToString()
                Dim oReason As DataTable = New DataTable
                oReason = odbutils.GetDataTable(gridSql)

                Dim rComboBox As RadComboBox = editor.ComboBoxControl

                rComboBox.DataSource = oReason
                rComboBox.DataTextField = "DisplayValue"
                rComboBox.DataValueField = "PK_PickList"
                rComboBox.DataBind()

                Dim drVal = DirectCast(e.Item.DataItem, DataRowView)
                If drVal IsNot Nothing Then
                    editor.SelectedValue = drVal("Reason_not_met").ToString()

          
                    Dim dtExpected As RadDatePicker = DirectCast(editedItem("Expected_Date").Controls(0), RadDatePicker)
                    If drVal("Expected_Date") IsNot Nothing Then
                        If Not String.IsNullOrEmpty(drVal("Expected_Date").ToString) Then
                            dtExpected.SelectedDate = drVal("Expected_Date")
                        End If
                    End If

                 
                End If
            End If




                
  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1796 posts

    Posted 13 Jan 2015 Link to this post

    Hi Vidya,

    Batch Editing is a client-side oriented edit mode and you can not use the server-side approaches that are used with the other edit modes. Furthermore, there is only one editor generated for the entire column and not an editor for each item.

    Detailed information on Batch editing and how to handle different scenarios is available in the following help article:
    Hope this helps.


    Regards,
    Konstantin Dikov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. shashi
    shashi avatar
    24 posts
    Member since:
    Jan 2016

    Posted 08 Jun Link to this post

    I am facing the issue with batchedit when I am trying to get the dropdown list from the grid edit row and append its list with new item. All this am trying to do in a client function "Batcheditopening".
  5. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1796 posts

    Posted 13 Jun Link to this post

    Hello Shashi,

    For getting reference to a control within the cell you need to handle the OnBatchEditOpened event and us the $telerik.findControl(container, id) for controls from our suite or $telerik.findElement(container, id) for standard controls. In the context of the Batch editing, the container should be the TD (cell) element for which the event fires.

    As for adding items dynamically you could refer to the following help topic:
    Hope this helps.


    Regards,
    Konstantin Dikov
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  6. shashi
    shashi avatar
    24 posts
    Member since:
    Jan 2016

    Posted 13 Jun in reply to Konstantin Dikov Link to this post

    Thanks for the reply.
    But I am still not able to make it work.
    I am able to find the control by using row but with cell I am not able to find.I have tried the following code.

    function BatcheditOpened(sender, args) {

                   
                    var row = args.get_row();
                    var cell = args.get_cell();
                    var columnUniquename = args.get_columnUniqueName();
                    var indexval = columnUniquename.split('_');
                    var labelval = $telerik.findElement(row, "lblday" + indexval[4]).attributes["expected"].nodeValue;
                    var dropdown = $telerik.findElement(row, "ddCareUnit1");   //this is working
                  //  var dropdown1 = $telerik.findElement(cell, "ddCareUnit1");  //it's not working
                }
    Now I have to add an item to the drop downlist. Can you please provide me working code for it.
    I am using the following grid structure.

    telerik:RadGrid ID="rgProvrAtndcInvNew" runat="server"  AllowPaging="True" GridLines="Both" 
                                CssClass="table-responsive rad-width" AutoGenerateColumns="false" ShowGroupPanel="false"
                                 MasterTableView-ExpandCollapseColumn-Visible="false" MasterTableView-ExpandCollapseColumn-Display="false"
                                 PageSize="20" OnNeedDataSource="rgProvrAtndcInvNew_NeedDataSource" OnBatchEditCommand="rgProvrAtndcInvNew_BatchEditCommand" >
                                <ClientSettings>
                                    <Scrolling AllowScroll="true" UseStaticHeaders="true" SaveScrollPosition="true" FrozenColumnsCount="3" />
                                    <ClientEvents  OnBatchEditOpening="BatcheditOpening" OnBatchEditOpened="BatcheditOpened" />
                                </ClientSettings>
                       <AlternatingItemStyle Font-Size="11px" HorizontalAlign="Center" />
                                <HeaderStyle Font-Bold="True" Font-Size="11px" Height="25px" HorizontalAlign="Center"   />
                                <ItemStyle Font-Size="11px" HorizontalAlign="Center" />
                                      <PagerStyle PagerTextFormat="{4}{5} records in {1} pages" />
                        <MasterTableView AutoGenerateColumns="False" ShowHeadersWhenNoRecords="true" EditMode="Batch" TableLayout="fixed"  Width="100%" CssClass="radgridtest table table-striped table-hover table-bordered text-center" >
                            <BatchEditingSettings EditType ="cell" OpenEditingEvent="MouseUp" />
      <ColumnGroups>
                                <telerik:GridColumnGroup Name="ClientName" HeaderText="&nbsp;"></telerik:GridColumnGroup>
                                <telerik:GridColumnGroup Name="Day1" ></telerik:GridColumnGroup>
                                <telerik:GridColumnGroup Name="Day2" HeaderText="2"></telerik:GridColumnGroup>
                               .....
                                <telerik:GridColumnGroup Name="Day31" HeaderText="31"></telerik:GridColumnGroup>
                            </ColumnGroups>
    <Columns>
    <telerik:GridTemplateColumn HeaderText="1" UniqueName="CDE_TYPE_UNIT_CARE_1" ColumnGroupName="Day1">
                                     <ItemTemplate>
                                                 <asp:Label ID="lblday1" runat="server" Text='<%# Eval("CDE_TYPE_UNIT_CARE_1") %>' ToolTip="test" ></asp:Label>
                                     </ItemTemplate>
                                    <EditItemTemplate>
                                       
                                            <asp:DropDownList runat="server" ID="ddCareUnit1" ClientIDMode="Static" DataTextField="DISPLAYVALUE" DataValueField="KEYVALUE" CssClass=""> </asp:DropDownList>
                                            </EditItemTemplate>

                                </telerik:GridTemplateColumn>

                                <telerik:GridTemplateColumn HeaderText="2" UniqueName="CDE_TYPE_UNIT_CARE_2" ColumnGroupName="Day2">
                                     <ItemTemplate>
                                         <asp:Label ID="lblday2" runat="server" Text='<%# Eval("CDE_TYPE_UNIT_CARE_2") %>' ToolTip="test" ></asp:Label>                                   
                                    </ItemTemplate>
                                     <EditItemTemplate>
                                      
                                                <asp:DropDownList runat="server" ID="ddCareUnit2" ClientIDMode="Static" DataTextField="DISPLAYVALUE" DataValueField="KEYVALUE"> </asp:DropDownList>
                                            </EditItemTemplate>
                                </telerik:GridTemplateColumn>
    ........
    .....
     <telerik:GridTemplateColumn HeaderText="31" UniqueName="CDE_TYPE_UNIT_CARE_31" ColumnGroupName="Day31">
                                       <ItemTemplate>
                                        <asp:Label ID="lblday31" runat="server" Text='<%# Eval("CDE_TYPE_UNIT_CARE_31") %>'  ></asp:Label>                                   
                                    </ItemTemplate>
                                     <EditItemTemplate>
                                     
                                                <asp:DropDownList runat="server" ID="ddCareUnit31" ClientIDMode="Static" DataTextField="DISPLAYVALUE" DataValueField="KEYVALUE"> </asp:DropDownList>
                                            </EditItemTemplate>
                                </telerik:GridTemplateColumn>

    </Columns>

    I am Able to fill EditItemTemplate dropdownlist with database in grid prerender even.
    Now My requirement is to show the expected value of labels in the dropdoenlist during editing.
    Please help me with this scenario.

  7. Eyup
    Admin
    Eyup avatar
    3009 posts

    Posted 16 Jun Link to this post

    Hello Shashi,

    I've noticed that you are using static ClientIDMode for the dropdown control. Please note that setting ClientIDMode="Static" is not supported with any Telerik control in any scenario, not only Batch editing:
    http://www.telerik.com/forums/typeerror-a-get_postbackelement%28-%29-is-undefined#VgZ203DhP06ZuX5wx_iRVg


    Please make the suggested modification and let me know if it resolves the issue.

    Regards,
    Eyup
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  8. shashi
    shashi avatar
    24 posts
    Member since:
    Jan 2016

    Posted 16 Jun in reply to Eyup Link to this post

    Thanks for the help.

    Now I am able to find the dropdown and append a new item to it.

    but now it append an item for each cell of that column plz see the attached images.

    can I remove the item while closing the editor so it will not have multiple item for each click.

    Thanks in advance.

  9. shashi
    shashi avatar
    24 posts
    Member since:
    Jan 2016

    Posted 20 Jun Link to this post

    I got the solution for it.

    thanks for all the help.

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017