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

Dynamically Binding A GridDropDownColumn

1 Answer 347 Views
Grid
This is a migrated thread and some comments may be shown as answers.
K
Top achievements
Rank 1
K asked on 04 Jun 2013, 10:38 PM
I have several GridDropDownColumns that I would like to bind to data tables in the code behind class.
The examples I have seen show modifying the ItemDataBound method and testing to see if the control is in Edit mode. When I add this logic and debug it, it seems like it never gets into edit mode.  Therefore, I can't create an instance of the editor for the control and set the datasource and other properties.   How do I force the control into Edit mode?

Here is the code ASP.net code to define the grid:

  <asp:Panel ID="PnlPromoDetails" runat="server">
        <telerik:RadGrid ID="radGridPromoDetails" runat="server" Skin="Vista"
            AlternatingItemStyle-BackColor="#EDEDED" Width="1100px"
            AutoGenerateColumns="False" GridLines="None" OnNeedDataSource="DetailsGrid_NeedDataSource"
            OnItemDataBound="DetailsResultGrid_ItemDataBound" Height="16px" >
            <ClientSettings>
                <DataBinding EnableCaching="true" />
            </ClientSettings>
            <AlternatingItemStyle BackColor="#EDEDED" />
            <MasterTableView>
                <RowIndicatorColumn>
                    <HeaderStyle Width="20px" />
                </RowIndicatorColumn>
                <ExpandCollapseColumn>
                    <HeaderStyle Width="20px" />
                </ExpandCollapseColumn>
                <Columns>
                    <%--***********************************************--%>
                    <telerik:GridBoundColumn DataField="CampaignType"
                        HeaderText="Campaign&lt;/br&gt;Type" UniqueName="CampaignType">
                        <HeaderStyle Font-Bold="True" HorizontalAlign="Center" />
                        <ItemStyle HorizontalAlign="Center" />
                    </telerik:GridBoundColumn>
                    <%--***********************************************--%>
                    <telerik:GridDropDownColumn
                        DataSourceID=""
                        DataField=""
                        HeaderText="Account</br>Types"
                        UniqueName="chkAccountTypes" EmptyListItemText="(none)" ColumnEditorID="chkAccountTypes" Display="False">
                        <HeaderStyle Font-Bold="True" HorizontalAlign="Center"/>
                        <ItemStyle HorizontalAlign="Center" />
                    </telerik:GridDropDownColumn>

                </Columns>
                <GroupHeaderItemStyle Font-Bold="true" />
                <NoRecordsTemplate>
                    <asp:Label ID="lblNoPromoDetails" runat="server" Font-Bold="true"
                        ForeColor="Red" Text=""
                </NoRecordsTemplate>
            </MasterTableView>
        </telerik:RadGrid>
        </asp:Panel>



You will notice that I have not defined a data source from the drop down column.  I was hoping to do that programmatically.  The data table I have has one column in it called "LegalName" and the name of the table is "LegalInfo".  That table exists in the code behind.

I have worked on this all day and can't figure it out.  I hope someone can help.

I also thought of calling a method from the ASPX file to return the data table but that doesn't seem to work either.

I have looked at many examples of how to do this and none of them seem to work for me.

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 07 Jun 2013, 01:03 PM
Hello,

GridDropDownColumn has two render modes depending on the state of RadGrid. If the Grid is in display mode it renders no controls and sets the value directly to the TD element on the client. This value is taken from the DataField property provided in the column definition.

However, when in Edit mode the column Renders DropDown control for which the DataSourceID and ListValueField and LIstTextField properties are used.

Keeping this in mind, to which datasource you are referring to? To the display mode part of the column or to the Edit mode?

If you want the display mode then you should not check for IsInEditMode property in your ItemDataBound code.

You could check this help topic for more information on how to access controls in RadGrid.

Give this approach a try and you should not have problems.

Regards,
Andrey
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
K
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or