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

Dynamically setting source for GridDropDownColumn

6 Answers 73 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Carl
Top achievements
Rank 1
Carl asked on 10 Nov 2008, 01:26 AM

 

Dim ddlMyUniqueName As GridDropDownColumn = CType(theRadGrid.FindControl("MyUniqueName"), GridDropDownColumn)

gives the error that type Control cannot be converted to GridDropDownColumn.

I have had no problems dynamically setting the DataSourceId for a RadGrid in a Page_Load event. Why can't I do it for the DataSourceId on a GridDropDownColumn so I can use different sources on different pages for the same RadGrid control in a *.ascx control? What is the correct way to do this?

Also where is the best discussion (most clear yet also complete) that explains how to find and manipulate controls dynamically using the FindControl method? Is it consistent for all Telerik controls throughout the hierarchy of controls? Or does it vary depending on context in control lifecycle event?

 

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 10 Nov 2008, 07:13 AM
Hi Carl,

Try setting the DataSourceID for the GridDropDownColumn in the PageLoad event as shown below.

CS:
protected void Page_Load(object sender, EventArgs e)  
    { 
        foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns) 
        { 
            if ((col.UniqueName == "DropCol") && (col.ColumnType == "GridDropDownColumn")) 
            { 
                GridDropDownColumn DropCol = (GridDropDownColumn)col; 
                DropCol.DataSourceID = "SqlDataSource1"
                DropCol.DataField = "ProductID"
                DropCol.ListTextField = "ProductID"
            } 
        } 
    } 

Customize/Configure GridDropDownColumn

Thanks
Shinu.
0
Carl
Top achievements
Rank 1
answered on 10 Nov 2008, 04:44 PM
Well, thanks for the suggestions, but I'm still looking for a simple effective use of a "FindControl" method or a method that operates like a "FindControl" method. It should be easy to use, and it should not be what I'll call awkward. In other words, an effective "FindControl" method should NOT have to search through loops. If the "FindControl" method searches through loops then that search should be hidden in the internals of the "FindControl" method and the programmer should be able to call and use the "FindControl" method with a single line of code and WITHOUT having to write search loops.

I hope Telerik engineers are watching these threads in the Forums, and I hope that a new version of the Telerik controls will have a better more effective and simple use of a "FindControl" like method. So far in my experience with the Telerik controls, this problem remains the one that I find most unnecessarily awkward and frustrating.
0
Bob
Top achievements
Rank 1
answered on 10 Nov 2008, 07:25 PM
I'd like to second the idea that "FindControl"  just do what it sounds like it does, without devs writing loops to make it work.

This absolutely should be built in!
0
Carl
Top achievements
Rank 1
answered on 11 Nov 2008, 04:53 PM
Thanks, Bob, for seconding my call... 

Any Telerik admins monitoring this thread? Where do we post requests for features that we can vote on and build support for prioritizing in the next release?
0
Accepted
Yavor
Telerik team
answered on 13 Nov 2008, 06:36 AM
Hi Carl and Bob,

You can submit a feature request with a "Feature Request" form, available from your account. It is similar to a support ticket.
With respect to the issue at hand. The FindControl() method searches for controls nested in another naming container. In this case, the code supplied earlier is the correct one to get a reference to a column, since it has a much different interface. For the masterTableView, you have a FindColumn method, which caters for a similar approach to the one that you requested - you will not have to look through all the columns in the control:

.cs
protected void RadGrid1_PreRender(object sender, EventArgs e)  
    {  
        GridBoundColumn column = (GridBoundColumn)RadGrid1.MasterTableView.GetColumn("CustomerID");  
        //manipulate column further  
    } 

I hope this information helps.

Kind regards,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Carl
Top achievements
Rank 1
answered on 13 Nov 2008, 06:21 PM
Thanks!
Tags
Grid
Asked by
Carl
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Carl
Top achievements
Rank 1
Bob
Top achievements
Rank 1
Yavor
Telerik team
Share this question
or