Radcombobox inside Radgrid FormTemplate
G'day,
I have a RadComboBox control inside of a RadGrid that is displayed when the InitInsert action occurs. I'm using Entity Framework as a datasource & the results contained within this are correct. My problem is that when I use findcontrol it returns nothing.
If e.CommandName = "InitInsert" Then
RadGrid1.MasterTableView.InsertItemDisplay = Telerik.Web.UI.GridInsertItemDisplay.Bottom
Dim query = From myTable In dbEntity.myTables Select myTable.Name, myTable.ID
Dim mineCompBox = CType(e.Item.FindControl("mineCompBox"), RadComboBox) mineCompBox.DataSource = mineCompQuery mineCompRadBox.DataTextField = "Name" mineCompRadBox.DataValu开发者_运维问答eField = "Id" mineCompRadBox.DataBind()</code>
I'm having trouble finding any answers that reference FormTemplate without it being an edit form. What am I missing? :-(
Thanks.
I don't have my computer in front of me to test it but I'm pretty sure that either: 1) You are not looking at the right controls collection 2) or the RadComboBox is not create yet or has been created but the ID doesn't match so you cannot find it
Again not 100% sure. Maybe this can help you its a complete example: http://beecy.net/post/2009/01/07/telerik-radgrid-formtemplate-codebehind.aspx (maybe check you markup against this one)
My problem was solved by using an ItemCreated command. An example can be found here:
http://www.telerik.com/community/forums/aspnet-ajax/grid/find-controls-when-using-editcommand.aspx
The code for my situation was:
Private Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated
If TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode Then
Dim dbEntity As WebsiteEntities = New WebsiteEntities
Dim myQuery = From myTable In myTables Select myTable.Name, myTable.ID
Dim EditFormItem As GridEditFormItem = DirectCast(e.Item, GridEditFormItem)
Dim myCombobox As RadComboBox = DirectCast(EditFormItem.FindControl("radDropBox"), RadComboBox)
myCombobox.DataSource = myQuery
myCombobox.DataTextField = "Name"
myCombobox.DataValueField = "ID"
myCombobox.DataBind()
End If
End Sub
精彩评论