Radcombobox inside Radgrid FormTemplate

筅森魡賤 提交于 2019-12-08 04:46:26

问题


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.DataValueField = "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.


回答1:


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)




回答2:


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


来源:https://stackoverflow.com/questions/4201685/radcombobox-inside-radgrid-formtemplate

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!