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

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

7 Answers 552 Views
Grid
This is a migrated thread and some comments may be shown as answers.
vidya
Top achievements
Rank 1
vidya asked on 09 Jan 2015, 12:48 AM
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




            

7 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 13 Jan 2015, 09:18 AM
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.

 
0
shashi
Top achievements
Rank 1
answered on 08 Jun 2016, 10:40 PM
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".
0
Konstantin Dikov
Telerik team
answered on 13 Jun 2016, 10:12 AM
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.
0
shashi
Top achievements
Rank 1
answered on 13 Jun 2016, 05:05 PM
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.

0
Eyup
Telerik team
answered on 16 Jun 2016, 02:35 PM
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.
0
shashi
Top achievements
Rank 1
answered on 17 Jun 2016, 01:41 AM

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.

0
shashi
Top achievements
Rank 1
answered on 20 Jun 2016, 02:24 PM

I got the solution for it.

thanks for all the help.

Tags
Grid
Asked by
vidya
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
shashi
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or