You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: controls/formdecorator/troubleshooting/decorated-gridview-is-not-bound-to-sqldatasource-with-controlparameter .md
# Decorated GridView Is Not Bound to SqlDataSource with ControlParameter
12
12
13
-
This help article offers a solution to an issue where a decorated input's click event is not triggered when the input is followed by an HTML label element.
13
+
This help article offers a solution to an issue where a decorated asp:GridView by RadFormDecorator cannot be bound to an SqlDataSource with ControlParameter on initial page load.
14
14
15
15
**Problem:**
16
16
17
-
The client-side click event of decorated HTML input element of type "radio" or "checkbox" is not fired when the following conditions are met at the same time.
17
+
The asp:GridView cannot be bound on initial page load when it is decorated by RadFormDecorator and the GridView is bound to an SqlDataSource with ControlParameter. The issue can be reproduced with **Example 1**.
18
18
19
-
* The input is followed by a label element and there is not a whitespace between them.
19
+
>caption **Example 1**: Decorated asp:GridView is not visible on initial page load when it is bound to an SqlDataSource with ControlParameter.
* The "for" attribute of the label element and the "id" attribute of the input element are not declared.
22
44
23
45
**Cause:**
24
46
25
-
When a **RadFormDecorator** decorates "radio button" and "checkbox" HTML elements, it positions them outside of the visible viewport and then puts a label with a background image that represents the decorated input in their place.
47
+
In order to decorate all the controls on the page, the RadFormDecorator decorates the children controls of the complex controls as well (i.e., the RadFormDecorator iterates through the controls' collections).
48
+
49
+
There is, however, a binding issue with the GridView when an SqlDataSource is used with ControlParameter and at the same time the GridView's collection is accessed from the code behind. This issue can be easily reproduced on a page with no Telerik UI for ASP.NET AJAX controls and is shown in **Example 2**. The problem also affect the scenario with RadFormDecorator from **Example 1**.
50
+
51
+
>caption **Example 2**: asp:GridView cannot be bound to an SqlDataSource with ControlParameter when the GridView's collection is accessed from the code behind.
Before inserting a new label, however, the **RadFormDecorator** tries to set the corresponding background image to the HTML label element that follows the input element. This operation is performed because the control assumes a relation between the input and the following label. In scenarios where this association is missing (i.e., the "for" attribute of the label HTML element is not specified), however, the click event of the input will not be raised. The main purpose of the label HTML element is to create an association with an input element, so it is advisable to use the "for" attribute.
81
+
**VB**
82
+
83
+
Protected Sub Page_PreRender(sender As Object, e As EventArgs)
84
+
Dim c = GridView1.Controls
85
+
End Sub
28
86
29
-
This limitation is a consequence of the control's implementation and if the input-label relation cannot be created, one of the workarounds below must be used.
30
87
31
88
**Solution:**
32
89
33
90
There are a few options you can choose from, in order to handle the scenario described above.
34
91
35
-
*Declare the "for" and "id" attributes for the label and the input respectively. For example:
92
+
*Bind the DropDownList's data from the code behind instead of declaring the DataSourceID property of the DropDownList.
36
93
37
-
>caption **Example 1**: Associating a label to an input element by matching the input's "id" to the label's "for" attribute.
94
+
>caption **Example 3**: Binding DropDownList's data from the code behind instead of declaring its DataSourceID property.
* Insert a space between the input and the label - either in the markup (see an **Example 2**), or with JavaScript prior to the **RadFormDecorator**'s decoration (see an **Example 3**).
* Set the DataSourceID property of the DropDownList in the Page_Init event. This approach, however, will force the dropdownlist to rebind itself which may lead to performance issues for large data sources.
0 commit comments