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

get raddatePicker on ItemCommand

1 Answer 25 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 06 Nov 2014, 09:52 PM
I was trying to follow the same code here on a telerik web site, becuase I need to do the smae thing, however it keeps telling me that I cannot get ahold of the raddatePicker that I put on the editform template, I am guessing its cause i am binding to a datatable.  I need to be able to get a hold of the raddate and time pickers and store them in a session datatable until i insert them into  a database.


<telerik:RadGrid ID="myradGrid" runat="server" Skin="Web20" CssClass="CentGrid50" Visible="false">
                            <MasterTableView AutoGenerateColumns="true" ShowHeadersWhenNoRecords="true" CommandItemDisplay="Top">
                                <EditFormSettings EditFormType="Template">
                                    <FormTemplate>
                                        <table>
                                            <tr>
                                                <td>
                                                     <telerik:RadDatePicker ID="dtbegin" runat="server" Width="100px"></telerik:RadDatePicker>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                      <telerik:RadTimePicker ID="dtTimeBegin" runat="server" Width="100px">
                                                            <TimeView runat="server" Interval="00:30:00"></TimeView>
                                                        </telerik:RadTimePicker>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                      <telerik:RadTimePicker ID="RadTimePicker1" runat="server" Width="100px">
                                                            <TimeView runat="server" Interval="00:30:00"></TimeView>
                                                        </telerik:RadTimePicker>
                                                </td>
                                            </tr>
                                            <tr>
                                                  <td>
                                                    <asp:LinkButton ID="lnkSubmit" runat="server" text='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "Insert", "Update") %>'
                                                    CommandName='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "PerformInsert", "Update")%>'></asp:LinkButton>
                                                         
                                                    <asp:LinkButton ID="lnkCancel" runat="server" CausesValidation="false" CommandName="Cancel" Text="Cancel"></asp:LinkButton>
                                                </td>
                                            </tr>
                                        </table>
                                    </FormTemplate>
                                </EditFormSettings>
                            </MasterTableView>
                        </telerik:RadGrid>
 
 
 
 Protected Sub myradGrid_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs) Handles myradGrid.NeedDataSource
        Dim dt As New DataTable
        dt.Columns.Add("Date Begin")
        dt.Columns.Add("Time Begin")
        dt.Columns.Add("Time End")
 
        If Session("Table") IsNot Nothing Then
            dt = DirectCast(Session("Table"), DataTable)
        End If
 
        myradGrid.DataSource = dt
        'populate RadGrid with datatable
        Session("Table") = dt
    End Sub
 
 
Heres my code to try to get at the insert into the datatable but it will not allow me to get at the raddate or time pickers, says cannot be converted from table cell.
 
  Protected Sub myradGrid_ItemCommand(sender As Object, e As GridCommandEventArgs) Handles myradGrid.ItemCommand
        If (e.CommandName = RadGrid.PerformInsertCommandName) Then
            Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
            Dim dtbegin As RadDatePicker = DirectCast(editedItem("dtbegin"), RadDatePicker)
 
            Dim dt As DataTable
 
            dt = DirectCast(Session("Table"), DataTable)
            Dim drValues As DataRow = dt.NewRow()
            drValues("Date Begin") = dtbegin.Text
            drValues("Time Begin") = timeBegin.Text
            drValues("Time End") = timeEnd.Text
 
            dt.Rows.Add(drValues)
            'adding new row into datatable
            dt.AcceptChanges()
 
            Session("Table") = dt
 
            myradGrid.Rebind()
        End If
    End Sub

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 11 Nov 2014, 12:25 PM
Hello Kevin,

Please note that the editedItem("dtbegin") is a TableCell container. In order to access the mentioned controls, you need to use the FindControl method:
( Section Accessing controls in edit/insert mode )
http://www.telerik.com/help/aspnet-ajax/grid-accessing-cells-and-rows.html


Hope this helps. Please give it a try and let me know if it works for you.

Regards,
Eyup
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.

 
Tags
Grid
Asked by
Kevin
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or