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

Populate InsertItemTemplate from Dropdownlist

1 Answer 92 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 09 Jun 2020, 06:32 PM

I have a RadDataform, which has DropDownLists added to the Edit and Insert Item Templates :

<telerik:RadDataForm RenderMode="Lightweight" ID="FormCN" runat="server" 
                    OnNeedDataSource="FormCN_NeedDataSource" 
                    OnItemInserting="FormCN_ItemInserting"
                    OnItemUpdating="FormCN_ItemUpdating"
                    OnItemDeleting="FormCN_ItemDeleting"  
                    OnPreRender="FormCN_PreRender"                     
                    DataKeyNames="CN_SEQ"    
                    Skin="MetroTouch" >
         ...
                <ItemTemplate>
                  ...
                </ItemTemplate>
                    
                <EditItemTemplate>
                  ...
                        <div class="rdfRow">
                            <div class="rdfRight" >                               
                                <telerik:RadComboBox ID="cmbPrep" OnPreRender="cmbPrep_PreRender" OnSelectedIndexChanged="cmbPrep_SelectedIndexChanged" AutoPostBack="true" AllowCustomText="true" runat="server" Skin="MetroTouch" EmptyMessage="Prep" style="float:right;"></telerik:RadComboBox>                                               
                            </div>
                            <telerik:RadTextBox ClientEvents-OnLoad="setHeight" RenderMode="Lightweight" TextMode="MultiLine" ID="PREP" runat="server" Text='<%# Bind("PREP") %>' WrapperCssClass="rdfInput" />                            
                        </div>
                       ...
                </EditItemTemplate>

                <InsertItemTemplate>
                  ...
                        <div class="rdfRow">
                            <div class="rdfRight" >                               
                                <telerik:RadComboBox ID="cmbPrep2" OnPreRender="cmbPrep2_PreRender" OnSelectedIndexChanged="cmbPrep2_SelectedIndexChanged" AutoPostBack="true" AllowCustomText="true" runat="server" Skin="MetroTouch" EmptyMessage="Prep" style="float:right;"></telerik:RadComboBox>                                               
                            </div>
                            <telerik:RadTextBox ClientEvents-OnLoad="setHeight" RenderMode="Lightweight" TextMode="MultiLine" ID="PREP2" runat="server" Text='<%# Bind("PREP") %>' WrapperCssClass="rdfInput" />                            
                        </div>
                      ...
                </InsertItemTemplate>

 

Using NeedDataSource:

 Protected Sub FormCN_NeedDataSource(sender As Object, e As RadDataFormNeedDataSourceEventArgs)
        TryCast(sender, RadDataForm).DataSource = SourceDataTable
    End Sub

Public ReadOnly Property SourceDataTable() As DataTable
        Get
            Dim obj As [Object] = ViewState("SourceDataTable")
            If obj IsNot Nothing Then
                Return DirectCast(obj, DataTable)
            Else
                Dim strConnString As String = ConfigurationManager.ConnectionStrings(Session("mYear")).ConnectionString
                Dim con As OracleConnection = New OracleConnection(strConnString)

                cmdQuery = "SELECT QUEUE, BATCH_NUMBER, " &
                               "CN_SEQ, CN_YEAR, METHOD, " &
                               "PREPMETHOD, PREP, RECEIPT, " &
                               "SAMPPREP, SAMPANAL, CALIBRATION, " &
                               "BLANKS, SURROGATES, SPIKES, " &
                               "INTERNSTANDARD, SAMPLES, OTHER, " &
                               "DUPLICATES, SERIALDILUTION " &
                               "FROM CN_DETAILS " &
                               "WHERE QUEUE = '" & cmbQueue.SelectedValue & "' AND BATCH_NUMBER = " & cmbBatchNumber.SelectedValue & " "

                Dim cmd As OracleCommand = New OracleCommand(cmdQuery)

                cmd.Connection = con
                cmd.CommandType = CommandType.Text
                Dim da As OracleDataAdapter = New OracleDataAdapter(cmd)

                Dim dt As New DataTable()
                da.Fill(dt)
                ViewState("SourceDataTable") = dt
                Return dt

                cmd.Dispose()
                con.Close()
                con.Dispose()
            End If
        End Get

    End Property

On DropDownList Selected Item Changed, I need to populate it's associated textbox with the ddl value. This works well for the EditItem:

 Protected Sub cmbPrep_SelectedIndexChanged(sender As Object, e As RadComboBoxSelectedIndexChangedEventArgs)
        Dim cmbItem As RadComboBox = TryCast(sender, RadComboBox)
        Dim radTextBox As RadTextBox = cmbItem.Parent.FindControl("PREP")
        radTextBox.Text = e.Value.ToString
    End Sub

How do I replicate this functionalit for the InsertItem? I tried this:

Protected Sub cmbPrep2_SelectedIndexChanged(sender As Object, e As RadComboBoxSelectedIndexChangedEventArgs)
        Dim cmbItem As RadComboBox = TryCast(sender, RadComboBox)
        Dim radTextBox As RadDataFormInsertItem = cmbItem.Parent

        'radTextBox.Text = e.Value.ToString

        Dim insertedItem As RadDataFormInsertItem = TryCast(radTextBox, RadDataFormInsertItem)

        Dim newValues As New Hashtable()
        insertedItem.ExtractValues(newValues)
        newValues("PREP") = e.Value.ToString
        newValues("CN_SEQ") = 9999999
        newValues("CN_YEAR") = "2020"
        newValues("QUEUE") = cmbQueue.SelectedValue
        newValues("BATCH_NUMBER") = cmbBatchNumber.SelectedValue

        Dim dt As DataTable = ViewState("SourceDataTable")

        Dim newRow As DataRow = dt.NewRow()

        For Each entry As DictionaryEntry In newValues
            newRow(DirectCast(entry.Key, String)) = entry.Value
        Next

        dt.Rows.Add(newRow)
        ViewState("SourceDataTable") = dt
    End Sub

The corresponding InsertItem textbox is not updated, however, if you click cancel and return to View, the item text is there. What am I missing please?

1 Answer, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 12 Jun 2020, 02:39 PM

Hi Scott,

Have you tried to do the same in the InsertItemTempalte as in the EdititemTemplate?

Protected Sub cmbPrep_SelectedIndexChanged(sender As Object, e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs)

    Dim combo = DirectCast(sender, RadComboBox)

    Dim txtBox = TryCast(combo.NamingContainer.FindControl("PREP"), RadComboBox)

    txtBox.Text = combo.SelectedItem.Value

End Sub


Protected Sub cmbPrep2_SelectedIndexChanged(sender As Object, e As RadComboBoxSelectedIndexChangedEventArgs)
    Dim combo = DirectCast(sender, RadComboBox)

    Dim txtBox = TryCast(combo.NamingContainer.FindControl("PREP2"), RadComboBox)

    txtBox.Text = combo.SelectedItem.Value
End Sub

 

Kind regards,
Attila Antal
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
DataForm
Asked by
Scott
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
Share this question
or