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

Findcontrol on ItemDataBound event

4 Answers 179 Views
Grid
This is a migrated thread and some comments may be shown as answers.
dhuss
Top achievements
Rank 1
dhuss asked on 18 May 2010, 11:38 PM
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

Sort by
0
Accepted
Shinu
Top achievements
Rank 1
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:
 <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 ObjectByVal 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 "&nbsp;" 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
Iana Tsolova
Telerik team
answered on 20 May 2010, 12:50 PM
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.
0
dhuss
Top achievements
Rank 1
answered on 20 May 2010, 02:59 PM
that did the trick, thanks
Tags
Grid
Asked by
dhuss
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
dhuss
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or