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

GridDropDownColumns blank on postback

2 Answers 119 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul Taylor
Top achievements
Rank 1
Paul Taylor asked on 10 May 2011, 04:10 PM
I have a RadGrid with several GridDropDownColumns configured as well as several GridBoundColumns. The grid is bound to a data source programatically using the NeedDataSource event. The dropdown columns use RadComboBox style drop downs which are also bound to datasources programatically, in the grid's ItemDataBound event when the grid is in Edit mode. When the grid is not in Edit mode, I set the value of the dropdown column cell's Text property, also in the ItemDataBound event.

This all works are required. However if I do something that causes a postback, but does not rebind the grid when the grid is not in Edit mode - for example selecting a row in the grid - the values in the dropdown columns go blank. Is the TableCell.Text property not persisted through postback? If not, which property should I use for this purpose, or how can I populate it again, given that the ItemDataBound property does not fire which you simply select a row in the grid.

Code sample below:

<telerik:RadGrid runat="server" ID="grdControl" AllowFilteringByColumn="True" AllowPaging="True"
    AllowSorting="True" GridLines="None">
    <MasterTableView AutoGenerateColumns="False" EditMode="EditForms" DataKeyNames="ControlId, StepId"
        CommandItemDisplay="Bottom">
        <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
        <Columns>
            <telerik:GridButtonColumn ButtonType="LinkButton" Text="Select" CommandName="Select" UniqueName="Select">
            </telerik:GridButtonColumn>
            <telerik:GridEditCommandColumn UniqueName="Edit">
            </telerik:GridEditCommandColumn>
            <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="Delete">
            </telerik:GridButtonColumn>
            <telerik:GridDropDownColumn DataField="ControlName" HeaderText="Control Type" UniqueName="ControlName">
            </telerik:GridDropDownColumn>
            <telerik:GridBoundColumn DataField="MaxLength" HeaderText="Max Length" UniqueName="MaxLength">
            </telerik:GridBoundColumn>
            <telerik:GridDropDownColumn DataField="TextMode" HeaderText="Text Mode"
                UniqueName="TextMode" />
            <telerik:GridDropDownColumn DataField="ListSource" HeaderText="List Source" UniqueName="ListSource">
            </telerik:GridDropDownColumn>
            <telerik:GridBoundColumn DataField="EmptyListText" HeaderText="Empty List Text" UniqueName="EmptyListText">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
    <FilterMenu>
    </FilterMenu>
    <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
    </HeaderContextMenu>
</telerik:RadGrid>
 
 
 
        Private Sub grdControl_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles grdControl.ItemDataBound
            If TypeOf e.Item Is GridEditableItem Then
                Dim item As GridEditableItem = e.Item
                Dim control As FormControlInfo
                Dim ffc As New FlexFormController()
                If TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode Then
                    If e.Item.OwnerTableView.IsItemInserted Then
                        control = New FormControlInfo()
                    Else
                        control = e.Item.DataItem
                    End If
                    Dim editor As GridDropDownListColumnEditor
                    Dim cbo As RadComboBox
                    'ControlName dropdown
                    Dim path As String = Server.MapPath("~/DesktopModules/Dotcom.FlexForm/Components/FormControls/")
                    Dim files As String() = IO.Directory.GetFiles(path, "*.ascx")
                    For i = 0 To files.Length - 1
                        files(i) = IO.Path.GetFileName(files(i)).Replace(".ascx", String.Empty)
                    Next
                    editor = item.EditManager.GetColumnEditor("ControlName")
                    editor.DataSource = files
                    editor.DataBind()
                    editor.SelectedValue = control.ControlName
                    'ListSource dropdown
                    editor = item.EditManager.GetColumnEditor("ListSource")
                    Dim controller As New Lists.ListController()
                    Dim list As Lists.ListInfoCollection
                    If String.IsNullOrEmpty(control.ParentKey) Then
                        list = controller.GetListInfoCollection()
                        editor.DataTextField = "DisplayName"
                        editor.DataValueField = "Key"
                    Else
                        list = controller.GetListInfoCollection(Nothing, control.ParentKey.Replace(":", "."))
                        editor.DataTextField = "Name"
                        editor.DataValueField = "Name"
                    End If
                    editor.DataSource = list
                    editor.DataBind()
                    cbo = editor.ComboBoxControl
                    cbo.Items.Insert(0, New RadComboBoxItem(Localization.GetString("EmptyListItem", Definition.SharedResources), String.Empty))
                    If Not String.IsNullOrEmpty(control.ListSource) Then
                        editor.SelectedValue = control.ListSource
                    End If
                    'TextMode dropdown
                    editor = item.EditManager.GetColumnEditor("TextMode")
                    editor.DataSource = [Enum].GetNames(GetType(TextBoxMode))
                    editor.DataBind()
                    cbo = editor.ComboBoxControl
                    cbo.Items.Insert(0, New RadComboBoxItem(Localization.GetString("EmptyListItem", Definition.SharedResources), String.Empty))
 
                Else
                    control = e.Item.DataItem
                    item("ControlName").Text = control.ControlName
                    item("ListSource").Text = control.ListSource
                    item("EmptyListText").Text = Server.HtmlEncode(control.EmptyListText)
                    item("ParentControlId").Text = control.ParentId
                    If control.TextMode.HasValue Then
                        item("TextMode").Text = control.TextMode.Value.ToString
                    End If
                End If
            End If
        End Sub



2 Answers, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 13 May 2011, 02:10 PM
Hi Paul,

Indeed the Text property of the TableCell is not persisted across postback because when you change the value in the ItemDataBound event it is not tracked by the view state. You can either rebind the grid to cause ItemDataBound to fire again or you can manually persist those text values in Session or ViewState, and populate them again on postback in the correct cells. Another option will be if you could bind the GridDropDownColumn in the markup instead of code behind.
 
Kind regards,
Marin
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Vikas
Top achievements
Rank 1
answered on 03 Mar 2014, 09:09 PM
Paul, just wondering if you were able to resolve this issue. If yes, how?

Thanks,
Vikas
Tags
Grid
Asked by
Paul Taylor
Top achievements
Rank 1
Answers by
Marin
Telerik team
Vikas
Top achievements
Rank 1
Share this question
or