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

GridDropDownColumn DataField displaying blank in nonedit mode

1 Answer 121 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Warren
Top achievements
Rank 2
Warren asked on 05 Jun 2012, 12:54 PM
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"
        CommandItemDisplay="Top">
        <Columns>
            <telerik:GridBoundColumn DataField="Name"
                HeaderText="Dept"
                UniqueName="Name">
            </telerik:GridBoundColumn>
            <telerik:GridDropDownColumn ListTextField="Name" ListValueField="DepartmentId" DataField="Name"
                HeaderText="Department" DropDownControlType="DropDownList"
                UniqueName="OrgDept">
            </telerik:GridDropDownColumn>
            <telerik:GridBoundColumn DataField="DepartmentId"
                HeaderText="Speech Rec Object Id"
                MaxLength="255" UniqueName="DepartmentId">
            </telerik:GridBoundColumn>
            <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" />
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

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()
        editor.DataBind()
        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.
ScreenShot

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?

Thanks,

Warren

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 06 Jun 2012, 05:25 AM
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.

VB:
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

Thanks,
Shinu.
Tags
Grid
Asked by
Warren
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Share this question
or