I have a radGrid with Add a Record turned on and the edit is turned on for each row. How do I validate in the code behind if the user selected Add a Record or Edit an Existing?
I have a drop down list in the Insert and Edit modes. If the user selects add a new record, I want to populate the drop dwon list with all the values and the first one should be selected. If the user selects edit a record, I want the current value to display. I am getting the latter one to work.
| Protected Sub RadGrid1_EditCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.EditCommand |
| editSelected = True |
| Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem) |
| Dim statusLabel As Label |
| statusLabel = item.FindControl("lblStatus") |
| Session("updatedStatusValue") = statusLabel.Text.ToString() |
| Dim priorityLabel As Label |
| priorityLabel = item.FindControl("lblPriorityDesc") |
| Session("updatedPriorityValue") = priorityLabel.Text.ToString() |
| End Sub |
| Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound |
| If "matter".Equals(e.Item.OwnerTableView.Name) Then |
| If (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then |
| Dim item As GridEditableItem = e.Item |
| Dim ddlStatusList As DropDownList = item.FindControl("ddlStatus") |
| ddlStatusList.DataSource = GetStatusList() |
| ddlStatusList.DataBind() |
| If (Not Session("updatedStatusValue") Is Nothing) Or editSelected Then |
| For Each ddlItems As ListItem In ddlStatusList.Items |
| If ddlItems.Text = Session("updatedStatusValue") And editSelected Then |
| ddlStatusList.SelectedValue = ddlItems.Value |
| End If |
| Next |
| Else |
| ddlStatusList.SelectedValue = 1 |
| End If |
| Dim ddlPriorityList As DropDownList = item.FindControl("ddlPriorityDesc") |
| ddlPriorityList.DataSource = GetPriorityList() |
| ddlPriorityList.DataBind() |
| If (Not Session("updatedPriorityValue") Is Nothing) Or editSelected Then |
| For Each ddlItems As ListItem In ddlPriorityList.Items |
| If ddlItems.Text = Session("updatedPriorityValue") And editSelected Then |
| ddlPriorityList.SelectedValue = ddlItems.Value |
| End If |
| Next |
| Else |
| ddlPriorityList.SelectedValue = 1 |
| End If |
| End If |
| End If |
| End Sub |
Thanks,
Randy