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?