I have a radGrid that has GridboundColumns, GridNumericColumns, GridDateTimeColumns and GridClientSelectColumns. I need to find specfic columns when the ItemDatabound event fires. Each column has a unique name assigned to it. When I use the e.item.findcontrol("uniquename"), all I get is "Nothing". I am using vb.net (2008). What is the correct way to find a control based on the column types described above using the controls unique name property.
4 Answers, 1 is accepted
0
Accepted
Shinu
Top achievements
Rank 2
answered on 19 May 2010, 10:42 AM
Hello Dhuss,
The following example shows how to access the values and controis pplaced in different columns. I hope this would help you.
ASPX:
VB.NET
Regards,
Shinu.
The following example shows how to access the values and controis pplaced in different columns. I hope this would help you.
ASPX:
<telerik:GridBoundColumn DataField="FirstName" HeaderText="FirstName" UniqueName="GridBoundColumn1" /> |
<telerik:GridDateTimeColumn PickerType="DateTimePicker" DataType="System.DateTime" |
DataField="BirthDate" HeaderText="BirthDate" UniqueName="GridDateTimeColumn1"> |
</telerik:GridDateTimeColumn> |
<telerik:GridNumericColumn DataField="EmployeeID" HeaderText="EmployeeID" UniqueName="GridNumericColumn1" |
NumericType="Number"> |
</telerik:GridNumericColumn> |
<telerik:GridClientSelectColumn UniqueName="GridClientSelectColumn1"> |
</telerik:GridClientSelectColumn> |
VB.NET
Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs) |
If TypeOf e.Item Is GridDataItem Then |
Dim item As GridDataItem = DirectCast(e.Item, GridDataItem) |
Dim name As String = item("GridBoundColumn1").Text |
Dim dt As DateTime = Convert.ToDateTime(item("GridDateTimeColumn1").Text) |
Dim num As Integer = Convert.ToInt16(item("GridNumericColumn1").Text) |
Dim chk As CheckBox = DirectCast(item("GridClientSelectColumn1").Controls(0), CheckBox) |
End If |
End Sub |
Regards,
Shinu.
0
dhuss
Top achievements
Rank 1
answered on 19 May 2010, 05:09 PM
That did it, thank you. I did find something very odd though when binding the data. If a datacolumn in a datatable has a NULL value (this is what is in the SQL database), the griddataitem text returns " " instead of the empty string. See the attached screen shot. This has to be a bug because how would you every test for string.isnullorempty
0
Accepted
Hi dhuss,
You can overcome this behavior by setting the EmptyDataText property for the particular grid column.
Check it out and let me know if it works for you.
Sincerely yours,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
You can overcome this behavior by setting the EmptyDataText property for the particular grid column.
Check it out and let me know if it works for you.
Sincerely yours,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
dhuss
Top achievements
Rank 1
answered on 20 May 2010, 02:59 PM
that did the trick, thanks