Skip to content

Commit 8b45d5a

Browse files
github-actions[bot]KB Bot
andauthored
Added new kb article grid-styling-grid-dropdowncolumn-in-insert-mode (#681)
Co-authored-by: KB Bot <[email protected]>
1 parent 47ec973 commit 8b45d5a

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
title: Styling Items in GridDropDownColumn in Insert Mode with InPlace EditMode
3+
description: Learn how to customize the width, height, and font-size of dropdown items in a GridDropDownColumn while in Insert mode with InPlace EditMode in RadGrid for ASP.NET AJAX.
4+
type: how-to
5+
page_title: Customizing Dropdown Appearance in Insert Mode of GridDropDownColumn
6+
slug: grid-styling-grid-dropdowncolumn-in-insert-mode
7+
tags: radgrid, asp.net ajax, griddropdowncolumn, editmode, styling, itemdatabound, inplace-editmode
8+
res_type: kb
9+
ticketid: 1685934
10+
---
11+
12+
## Environment
13+
14+
<table>
15+
<tbody>
16+
<tr>
17+
<td>Product</td>
18+
<td>RadGrid for ASP.NET AJAX</td>
19+
</tr>
20+
<tr>
21+
<td>Version</td>
22+
<td>All</td>
23+
</tr>
24+
</tbody>
25+
</table>
26+
27+
## Description
28+
29+
I want to customize the appearance of the dropdown items in a **GridDropDownColumn** while in Insert mode using InPlace EditMode. Is there a way to achieve this effectively?
30+
31+
This knowledge base article also answers the following questions:
32+
- How to change the style of dropdown items in a RadGrid GridDropDownColumn during Insert mode?
33+
- Can I adjust the size and font of the dropdown in GridDropDownColumn while editing?
34+
- What is the proper way to style GridDropDownColumn items in InPlace EditMode?
35+
36+
## Solution
37+
38+
To customize the dropdown items in a **GridDropDownColumn** while in Insert mode, use the `ItemDataBound` event of the RadGrid and apply server-side adjustments combined with CSS. Follow these steps:
39+
40+
Set up the RadGrid with necessary columns and data sources, including a **GridDropDownColumn**.
41+
42+
````ASP.NET
43+
<telerik:RadGrid ID="RadGrid1" runat="server" Width="800px" AutoGenerateColumns="False" AllowPaging="true" DataSourceID="SqlDataSource1" OnItemDataBound="RadGrid1_ItemDataBound">
44+
<MasterTableView DataKeyNames="OrderID">
45+
<Columns>
46+
<telerik:GridEditCommandColumn />
47+
<telerik:GridBoundColumn DataField="OrderID" HeaderText="Order ID" ReadOnly="True" UniqueName="OrderID" />
48+
<telerik:GridDropDownColumn DataField="CustomerID" HeaderText="Customer" UniqueName="CustomerID" ListTextField="CompanyName" ListValueField="CustomerID" DataSourceID="SqlDataSource2" />
49+
</Columns>
50+
</MasterTableView>
51+
</telerik:RadGrid>
52+
53+
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
54+
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
55+
SelectCommand="SELECT OrderID, CustomerID FROM Orders"
56+
UpdateCommand="UPDATE Orders SET CustomerID = @CustomerID WHERE OrderID = @OrderID">
57+
<UpdateParameters>
58+
<asp:Parameter Name="CustomerID" Type="String" />
59+
<asp:Parameter Name="OrderID" Type="Int32" />
60+
</UpdateParameters>
61+
</asp:SqlDataSource>
62+
63+
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
64+
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
65+
SelectCommand="SELECT CustomerID, CompanyName FROM Customers ORDER BY CompanyName"></asp:SqlDataSource>
66+
````
67+
68+
Use the `ItemDataBound` event to modify the dropdown's appearance dynamically.
69+
70+
````C#
71+
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
72+
{
73+
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
74+
{
75+
GridEditableItem editItem = e.Item as GridEditableItem;
76+
RadComboBox comboBox = editItem.FindControl("RCB_CustomerID") as RadComboBox;
77+
78+
if (comboBox != null)
79+
{
80+
comboBox.Width = Unit.Pixel(300); // Set width
81+
comboBox.Height = Unit.Pixel(500); // Set height
82+
comboBox.Style.Add("font-size", "14px"); // Set font size
83+
}
84+
}
85+
}
86+
````
87+
88+
The ID of the RadComboBox in the GridDropDownColumn is dynamically generated. Use the format `RCB_<DataField>` to locate the control. For example, if the DataField is `CustomerID`, the ID will be `RCB_CustomerID`.
89+
90+
This approach allows you to effectively style the dropdown in Insert mode while using InPlace EditMode.
91+
92+
## See Also
93+
94+
- [RadGrid Documentation](https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/overview)
95+
- [RadComboBox Documentation](https://docs.telerik.com/devtools/aspnet-ajax/controls/combobox/overview)

0 commit comments

Comments
 (0)