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

How To Add a GridBoundColumn to Grid

5 Answers 446 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kurt
Top achievements
Rank 1
Kurt asked on 03 Jun 2013, 08:08 PM
I have query that returns several result sets.  One of these resultsets is turned into a table and bound to a grid.  That works fine.

I have two other result sets that return lists of values; let's call them aList and bList.  I will turn these into tables as well because I believe the GridBoundColumn was designed to work best with tables.

Here is my problem.  I am already specifying a resultset as a DataSouce for the grid. 

How do I get the GridBoundColumns in the grid mapped to the aList and bList tables?

Here is how the columns are defined:

 

 

<telerik:GridDropDownColumn

 

 

 

DataField="Office"

 

 

 

HeaderText="Offices"

 

 

 

UniqueName="chkOffices">

 

 

 

<HeaderStyle Font-Bold="True" HorizontalAlign="Center"/>

 

 

 

<ItemStyle HorizontalAlign="Center" />

 

 

 

</telerik:GridDropDownColumn>

 

<%

 

--***********************************************--%>

 

 

 

<telerik:GridDropDownColumn

 

 

 

DataField="TypeName"

 

 

 

HeaderText="Types"

 

 

 

UniqueName="chkTypes">

 

 

 

<HeaderStyle Font-Bold="True" HorizontalAlign="Center"/>

 

 

 

<ItemStyle HorizontalAlign="Center" />

 

 

 

</telerik:GridDropDownColumn>

 


I have a Bind method that is binding the table to the grid and it looks like this:

 

 

private void BindDetails(DataTable Details, DataTable List, DataTable TiersList, DataTable officeList)

 

{

 

 

RadGrid grid = radGridPromoDetails;

 

grid.

 

MasterTableView.SortExpressions.Clear();

 

grid.

 

CurrentPageIndex = 0;

 

grid.

 

DataSource = Details;

 

grid.

 

DataBind();

 

}


The XML from the resultset is in the following form:
<Details>
  <field1></field1>
  <field2></field2>
  <Types></Types> -- this is the first dataset that I want to display in a drop down in a grid row.
  <Offices></Offices> -- this is the second dataset that  I want to display in a drop down in a grid row.
</Details>

Any ideas?

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 Jun 2013, 05:13 AM
Hi Kurt,

I'm not sure about your scenario.Please elaborate on your requirements.
RadGrid does not support mixing declarative grid columns with grid columns added dynamically at runtime. You should either create all the columns in the grid programmatically, or else define them all in the ASPX file. You can find out the same mentioned in the following help document:
Programmatic Creation

Thanks
Princy
0
K
Top achievements
Rank 1
answered on 04 Jun 2013, 03:42 PM
Hi Princy,
I noticed that the title of my post was inaccurate.  It should have read: "...GridDropDownColumn" instead of "...GridBoundColumn".

I am declaring everything in code.  The grid is declared in a panel and the drop downs are declared as columns of the grid. 
I can declare them, I just can't figure out how to populate the drop downs with list data (which will be in the form of a Data Table).

The requirement is that I can populate the GridDropDownColumns with a list of values coming from DataTables.

Here is the code:

    <asp:Panel ID="PnlDetails" runat="server">
        <telerik:RadGrid ID="radGridDetails" 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="Type"
                        HeaderText="&lt;/br&gt;Type" UniqueName="Type">
                        <HeaderStyle Font-Bold="True" HorizontalAlign="Center" />
                        <ItemStyle HorizontalAlign="Center" />
                    </telerik:GridBoundColumn>
                    <%--***********************************************--%>
                    <telerik:GridBoundColumn DataField="ShortName"
                        HeaderText="&lt;/br&gt;Name" UniqueName="ShortName">
                        <HeaderStyle Font-Bold="True" HorizontalAlign="Center" />
                        <ItemStyle HorizontalAlign="Center" />
                    </telerik:GridBoundColumn>
                    <%--***********************************************--%>
                    <telerik:GridBoundColumn DataField="StartDate"
                        DataFormatString="{0:MM/dd/yyyy}" HeaderText="Enroll&lt;/br&gt;Start Date"
                        UniqueName="StartDate">
                        <HeaderStyle Font-Bold="True" HorizontalAlign="Center" />
                        <ItemStyle HorizontalAlign="Center" />
                    </telerik:GridBoundColumn>
                    <%--***********************************************--%>
                    <telerik:GridBoundColumn DataField="EndDate" DataFormatString="{0:MM/dd/yyyy}"
                        HeaderText="Enroll&lt;/br&gt;End Date" UniqueName="EndDate">
                        <HeaderStyle Font-Bold="True" HorizontalAlign="Center" />
                        <ItemStyle HorizontalAlign="Center" />
                    </telerik:GridBoundColumn>
                    <%--***********************************************--%>
                    <telerik:GridBoundColumn DataField="QEndDate"
                        DataFormatString="{0:MM/dd/yyyy}" HeaderText="Q End&lt;/br&gt;Date"
                        UniqueName="QEndDate">
                        <HeaderStyle Font-Bold="True" HorizontalAlign="Center" />
                        <ItemStyle HorizontalAlign="Center" />
                    </telerik:GridBoundColumn>
                    <%--***********************************************--%>
                    <telerik:GridDropDownColumn
                        DataField="LegalTypeName"
                        HeaderText="Account</br>Types"
                        UniqueName="chkAccountTypes">
                        <HeaderStyle Font-Bold="True" HorizontalAlign="Center"/>
                        <ItemStyle HorizontalAlign="Center" />
                    </telerik:GridDropDownColumn>
                    <%--***********************************************--%>
                    <telerik:GridDropDownColumn
                        DataField="Office"
                        HeaderText="Offices"
                        UniqueName="chkOffices">
                        <HeaderStyle Font-Bold="True" HorizontalAlign="Center"/>
                        <ItemStyle HorizontalAlign="Center" />
                    </telerik:GridDropDownColumn>

                    <%--***********************************************--%>
                </Columns>
                <GroupHeaderItemStyle Font-Bold="true" />
                <NoRecordsTemplate>
                    <asp:Label ID="lblNoDetails" runat="server" Font-Bold="true"
                        ForeColor="Red" Text="There are no details for this tion." />
                </NoRecordsTemplate>
            </MasterTableView>
        </telerik:RadGrid>
        </asp:Panel>


0
Princy
Top achievements
Rank 2
answered on 05 Jun 2013, 03:57 AM
Hi K,

Please have a look at the following documentation,and try if this helps.
Customize/Configure GridDropDownColumn

Thanks,
Princy
0
K
Top achievements
Rank 1
answered on 05 Jun 2013, 03:59 PM
The c# code is actually what I need.  The problem is I will never be in Edit mode since I am just displaying read-only data.  I don't want the user to edit anything, I just want to show them the related items in the drop down list.  So, the following code won't work for me.

protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem editedItem = e.Item as GridEditableItem;
        GridEditManager editMan = editedItem.EditManager;
        GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("<MyDropDownColumnUniqueName>"));
        //in case you have RadComboBox editor for the GridDropDownColumn (this is the default editor),  
        //you will need to use ComboBoxControl below instead of DropDownListControl   
        //and add RadComboBoxItems instead of ListItems to the Items collection of the editor
        DropDownList ddList = editor.DropDownListControl;
        ddList.Items.Insert(0, new ListItem("Select Contact Title", "NotSetItem"));
        ddList.Items[0].Attributes["style"] = "color: red";
    }
}

0
Princy
Top achievements
Rank 2
answered on 06 Jun 2013, 08:12 AM
Hi K,

I guess you want to show the dropdown list values in view mode,but it is not possible when you use GridDropDownColumn,it just acts as a column cell in view mode,only in edit mode will it display as a dropdown list.
If you want to show the values as in dropdown list you can simply use an asp:dropdowwnlist,or telerik:raddropdownlist in ItemTemplate.

Thanks,
Princy
Tags
Grid
Asked by
Kurt
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
K
Top achievements
Rank 1
Share this question
or