GridDropDownColumn DataField displaying blank in nonedit mode

2 posts, 0 answers
  1. Warren
    Warren avatar
    24 posts
    Member since:
    May 2008

    Posted 05 Jun 2012 Link to this post

    I'm using ASP.NET AJAX Q1 2012 SP1.  I have a RadGrid with a GridDropDownColumn.  The RadGrid is populated on server side from the RadGrid's NeedDataSource event.  Everything is working except the expected DataField value is blank when the grid is in a non edit mode.  To test I even added a GridBoundColumn with the same DataField name to show that it does have a value.

    <telerik:RadGrid ID="rgDepartment" runat="server" Skin="Office2007"
        AutoGenerateColumns="False" AutoGenerateDeleteColumn="True" CellSpacing="0"
        GridLines="None" AllowMultiRowEdit="true">
        <MasterTableView DataKeyNames="OrgDepartmentId" AutoGenerateColumns="false" EditMode="InPlace"
                <telerik:GridBoundColumn DataField="Name"
                <telerik:GridDropDownColumn ListTextField="Name" ListValueField="DepartmentId" DataField="Name"
                    HeaderText="Department" DropDownControlType="DropDownList"
                <telerik:GridBoundColumn DataField="DepartmentId"
                    HeaderText="Speech Rec Object Id"
                    MaxLength="255" UniqueName="DepartmentId">
                <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" />

    Server side programming.
    Protected Sub rgDepartment_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles rgDepartment.ItemDataBound
        If (TypeOf e.Item Is GridEditableItem AndAlso CType(e.Item, GridEditableItem).IsInEditMode) Then
            Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
            ' Hides the Update button for each edit form
            editedItem("EditCommandColumn").Controls(0).Visible = False
            ' Apply the text box style
            CType(editedItem("DepartmentId").Controls(0), TextBox).CssClass = "TextBoxStyle"
            ' Populate drop down
            Dim editMan As GridEditManager = editedItem.EditManager
            Dim editor As GridDropDownColumnEditor = CType(editMan.GetColumnEditor("OrgDept"), GridDropDownColumnEditor)
            editor.DataSource = GetOrganizationDepartmentData()
            If e.Item.OwnerTableView.IsItemInserted = False AndAlso e.Item.DataItem("OrgDepartmentId") IsNot Nothing AndAlso e.Item.DataItem("OrgDepartmentId") > 0 Then
                editor.SelectedValue = e.Item.DataItem("OrgDepartmentId").ToString()
            End If
        End If
    End Sub
    Protected Sub rgDepartment_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles rgDepartment.NeedDataSource
        rgDepartment.DataSource = GetDeptData() ' Get Dataset
    End Sub

    Here is a screenshot of the web page.

    The only way I can think of getting this to work is to set the cells text to the data value within the ItemDataBound event.  Something like this.
    If (TypeOf e.Item Is GridDataItem AndAlso e.Item.IsInEditMode = False) Then
        Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)
        dataItem("OrgDept").Text = e.Item.DataItem("Name")
    End If

    Is this a known bug or am I doing something wrong?


  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 06 Jun 2012 Link to this post

    Hi Warren Reinke,

    Since you are binding the DropDownList in the edit mode, the value will only be shown in the edit mode.Try the following code snippet to show the DropDownList value in non edit mode also.

    Protected Sub rgDepartment_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs)
        If TypeOf e.Item Is GridDataItem AndAlso Not e.Item.IsInEditMode Then
            Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
            Dim row As DataRowView = DirectCast(e.Item.DataItem, DataRowView)
            item("OrgDept").Text = row("Name").ToString()
        End If
    End Sub

Back to Top