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

put value in textbox after changing combobox

1 Answer 121 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mydatafactory
Top achievements
Rank 1
Mydatafactory asked on 07 Jul 2008, 12:19 PM
I keep struggling with the following issue: In the editform of a hierarchical grid I have a combobox called ddlStatus. When the status changes into 'Accepted' an automatic mail must be sent. This is no problem.
Here's my issue: when the status changes into 'Accepted' the RadDateInput 'DateSendDataSteward'  must automatically be filled with the date of today. I tried it with several codes (see my last one on row 67 to 70), but decided to post a thread on the forum.

    Protected Sub gvProjects_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles gvProjects.ItemCommand  
        'trigger for retrieving the ProjectId  
        If (e.CommandName = RadGrid.UpdateCommandName AndAlso e.Item.OwnerTableView.DataSourceID = "dsTasks") Then  
            Dim TaskId As String = e.Item.OwnerTableView.Items(e.Item.ItemIndex)("TaskId").Text  
            gvProjects.Controls.Add(New LiteralControl("Updated item primary key value is: " & TaskId & "<br/>"))  
 
            
            If TypeOf e.Item Is GridDataItem Then  
                Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)  
                Dim chkbxlst As CheckBoxList = DirectCast(item("TempCol").FindControl("chkTasks"), CheckBoxList)  
            End If  
 
            Dim editItem As GridEditFormItem = CType(e.Item, GridEditFormItem)  
 
            Dim ddlStatus As RadComboBox = TryCast(FindControl("ddlStatus"), RadComboBox)  
            Dim cell1 As TableCell = editItem("ddlStatus")  
            Dim Status As String = (CType(cell1.Controls(0), RadComboBox)).Text  
 
            Dim DateSendDataSteward As RadDateInput = TryCast(FindControl("DateSendDataSteward"), RadDateInput)  
            Dim cellx As TableCell = editItem("DateSendDataSteward")  
            Dim MailDataSteward As String = (CType(cellx.Controls(0), RadDateInput)).Text  
 
           
 
           
            If Status = "Accepted" Then  
                If MailDataSteward = "" Then  
 
                    Dim cell2 As TableCell = editItem("TaskDescription")  
                    Dim Task As String = (CType(cell2.Controls(0), TextBox)).Text  
                    Dim cell3 As TableCell = editItem("EstimatedReadyDate")  
                    Dim EstimatedReadyDate As String = (CType(cell3.Controls(0), RadDatePicker)).SelectedDate  
                    Dim cell4 As TableCell = editItem("UserId")  
                    Dim User As Integer = (CType(cell4.Controls(0), RadComboBox)).SelectedValue  
 
 
                    Dim sql As String = _ 
                "Select UserId, Username, Name, Mailaddress " & _  
                "from tblUsers " & _  
                        "where UserId = '" & User & "'"  
                    Dim dr As SqlDataReader  
                    dr = DBPortal.OpenReader(sql)  
                    If dr.Read Then  
                        Dim Name As String = dr("Name").ToString  
                        Dim MailAddress As String  
 
 
                        MailAddress = dr("mailaddress")  
 
                        Dim Mail As New MailMessage  
                        Mail.To.Add(MailAddress)  
 
                        Mail.Subject = "New task" 
                        Mail.Body = "Dear " & Name & "," & vbCrLf & vbCrLf & "Here's a new task for you." & vbCrLf & vbCrLf & "Taskname: " & Task & vbCrLf & "Deadline: " & EstimatedReadyDate & vbCrLf & vbCrLf & "Ga naar www.DataPlanner.nl. "  
 
                        Try  
                            Dim client As New SmtpClient()  
                            client.Send(Mail)  
                        Catch ex As Exception  
 
                            While Not (ex.InnerException Is Nothing)  
                                exex = ex.InnerException  
                            End While  
                        End Try  
                    End If  
                    Dim Today As Date  
                    Today = Now()  
                    Dim editItemx As GridEditFormItem = CType(e.Item, GridEditFormItem)  
 
                    editItemx("DateSendDataSteward").Text = Today 
 
 
 
                End If  
 
            End If  
           
            Dim parentItem As GridDataItem = e.Item.OwnerTableView.ParentItem  
 
            If (Not parentItem Is Nothing) Then  
                gvProjects.Controls.Add(New LiteralControl("Parent item primary field value is: " & _  
                CType(parentItem.OwnerTableView.DataKeyValues(parentItem.ItemIndex)("ProjectId"), String)))  
            End If  
 
 
        End If  
        If (e.CommandName = RadGrid.InitInsertCommandName Or e.CommandName = RadGrid.PerformInsertCommandName) Then  
            'If (e.Item.OwnerTableView.DataSourceID = "dsTasks") Then  
            Dim parentItem = CType(e.Item.OwnerTableView.ParentItem, GridDataItem)  
 
            If (Not parentItem Is Nothing) Then  
                gvProjects.Controls.Add(New LiteralControl("Parent item primary field value is: " & _  
                CType(parentItem.OwnerTableView.DataKeyValues(parentItem.ItemIndex)("ProjectId"), String)))  
            End If  
            'End If  
        End If  
 
 
    End Sub 

1 Answer, 1 is accepted

Sort by
0
Mydatafactory
Top achievements
Rank 1
answered on 07 Jul 2008, 02:21 PM
I found the solution myself, eventually...

I've deleted the code in line 67 to 70 and replaced the code in line 19 to 21 by the code in line 1 to 3 below.
I've deleted the code in lin 27 and replaced it by code in line 8 to 11 below.

Now it works as I wanted it to work.
            Dim editeditem As GridEditableItem = DirectCast(e.Item, GridEditableItem)  
            Dim rdi As RadDateInput = DirectCast(editeditem("DateSendDataSteward").Controls(0), RadDateInput)  
            Dim strVal As String = rdi.Text  
 
 
           
            If Status = "Accepted" Then  
                If strVal = "" Then  
                    Dim Today As Date  
                    Today = Now()  
                    rdi.SelectedDate = Today 
Tags
Grid
Asked by
Mydatafactory
Top achievements
Rank 1
Answers by
Mydatafactory
Top achievements
Rank 1
Share this question
or