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

RadCombo in grid editform

10 Answers 729 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andy Green
Top achievements
Rank 2
Andy Green asked on 31 Mar 2009, 08:59 PM
Hi

THis is my aspx code its is a RadCombobox in a Radgrid form template:

<

 

EditFormSettings EditFormType="Template">

 

 

<EditColumn CancelImageUrl="../App_Themes/Expert/Grid/Cancel.gif" EditImageUrl="../App_Themes/Expert/Grid/Edit.gif" InsertImageUrl="../App_Themes/Expert/Grid/Update.gif" UpdateImageUrl="../App_Themes/Expert/Grid/Update.gif" ButtonType="ImageButton" UniqueName="EditCommandColumn1" ></EditColumn>

 

 

<FormTemplate>

 

 

 

 

 

 

 

<div>

 

 

<label class="gridlabel">Completed By:</label>

 

 

<telerik:RadComboBox ID="txtCompleteBy" runat="server" AccessKey="m" EmptyMessage="Key Worker" EnableEmbeddedSkins="False" Skin="Expert" Width="225px">

 

 

<CollapseAnimation Duration="200" Type="OutQuint" />

 

 

</telerik:RadComboBox>

 

 

</div>

 

 

 

 

</FormTemplate>

 

 

</EditFormSettings>

 

 
How do I fill this from code behind I have the data classes already:

Dim Keyworker_lkp As New clsExpert

 

Dim Keyworker_dt As DataTable = Keyworker_lkp.PractitionerLookup(Membership.GetUser().ProviderUserKey) 

I've searched the forums but nothing seems to fit.

Andy

 

10 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 01 Apr 2009, 04:51 AM
Hello Andy,

You can access the combobox and then set its datasource from the code behind as shown below:
c#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
       if (e.Item is GridEditFormItem && e.Item.IsInEditMode) 
        { 
            GridEditFormItem editFormItem = (GridEditFormItem)e.Item; 
            RadComboBox txtCompleteBy = (RadComboBox)editFormItem.FindControl("txtCompleteBy"); 
            txtCompleteBy.DataSource = Keyworker_dt; 
        } 
    } 

Thanks
Princy.
0
Andy Green
Top achievements
Rank 2
answered on 01 Apr 2009, 12:14 PM
Great thanks - had to play as my control was on a nested grid, but you code worked fine.
One last thing, how would I set the selected value to the id in my database
Andy
0
Tsvetoslav
Telerik team
answered on 02 Apr 2009, 02:23 PM
Hi Andy Green,

In the mark-up for your RadComboBox, just add:

SelectedValue='<%#Bind("YourDataField") %>' 

I hope this helps.

Best Regards,
Tsvetoslav
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Andy Green
Top achievements
Rank 2
answered on 02 Apr 2009, 02:38 PM
Tried this and it doesn't work,

It errors with a message that says that you can only use eval, bind for databound controls, I'm doing my databinding in code behind.

Andy
0
Shinu
Top achievements
Rank 2
answered on 03 Apr 2009, 05:09 AM
Hi Andy,

Try setting the AppendDataBoundItems property of the RadComboBox to true. Also set the SelectedValue of the ComboBox from the code behind. Here I have set the required DataField as the DataKeyName and set the SelectedValue of the ComboBox with key value.

Give a try with the following approach and see if it helps.

ASPX:
 
<MasterTableView  DataKeyNames="ProductName" > 

 
 
 <EditFormSettings EditFormType="Template"
                     <FormTemplate> 
                         <telerik:RadComboBox ID="RadComboBox2"  AppendDataBoundItems="true" runat="server"
                         </telerik:RadComboBox> 
                     </FormTemplate> 
                </EditFormSettings> 

CS:
 
 
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
 {  
        
        if((e.Item is GridEditFormItem)&&(e.Item.IsInEditMode))  
        {  
            GridEditFormItem editform = (GridEditFormItem)e.Item;  
            RadComboBox combo = (RadComboBox)editform.FindControl("RadComboBox2");  
            //bind the combobox here  
           // combo.DataSource=  
           //set the selected value with key name  
            combo.SelectedValue = editform.GetDataKeyValue("ProductName").ToString();  
  
        }  
  }  
 
 

Thanks
Shinu
0
Tsvetoslav
Telerik team
answered on 03 Apr 2009, 02:01 PM
Hello Andy,

Even if you are binding your combo in code behind, the binding expression in the mark-up should work as expected. The only thing to take into consideration is that you should use the ItemCreated event for the assignment of the combo's datasource property.

For your convenience, I am sending you a small sample demonstrating how to do that.

Please, review it for comparison with your implementation and let us know if we can help you further.

Sincerely yours,
Tsvetoslav
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Andy Green
Top achievements
Rank 2
answered on 04 Apr 2009, 08:38 AM

I Still cant get this working.

This is the markup fo the radcombo:

<label class="gridlabel">Observed By:</label>
<telerik:RadComboBox ID="txtObservedBy" runat="server" EmptyMessage="Key Worker"  EnableEmbeddedSkins="False" Skin="Expert"  Width="225px" SelectedValue='<%#Bind("Practitioner_ID") %>'>
<CollapseAnimation Duration="200" Type="OutQuint" />
</telerik:RadComboBox>

This is my code behind: I also get the same error if I use the ItemDataBound event

Protected Sub rgProfileMain_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgProfileMain.ItemCreated

        'fill edit form dropdown list
        If TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode Then
            Dim whichGrid As String = e.Item.OwnerTableView.Name

            Select Case whichGrid

                Case "Profile"

                    Dim editFormItem As GridEditFormItem = DirectCast(e.Item, GridEditFormItem)
                    Dim txtCompleteBy As RadComboBox = DirectCast(editFormItem.FindControl("txtCompleteBy"), RadComboBox)

                    Dim Keyworker_lkp As New clsExpert
                    Dim Keyworker_dt As DataTable = Keyworker_lkp.GetPractitionerByProvider(Membership.GetUser().ProviderUserKey)

                    If Keyworker_dt.Rows.Count > 0 Then
                        txtCompleteBy.AllowCustomText = True
                        txtCompleteBy.DataSource = Keyworker_dt
                        txtCompleteBy.DataValueField = "Practitioner_ID"
                        txtCompleteBy.DataTextField = "Practitioner_Name"
                        txtCompleteBy.DataBind()
                    End If

                Case "Observations"

                    Dim editFormItem As GridEditFormItem = DirectCast(e.Item, GridEditFormItem)
                    Dim txtObservedBy As RadComboBox = DirectCast(editFormItem.FindControl("txtObservedBy"), RadComboBox)

                    Dim Keyworker_lkp As New clsExpert
                    Dim Keyworker_dt As DataTable = Keyworker_lkp.GetPractitionerByProvider(Membership.GetUser().ProviderUserKey)

                    If Keyworker_dt.Rows.Count > 0 Then
                        txtObservedBy.AllowCustomText = True
                        txtObservedBy.DataSource = Keyworker_dt
                        txtObservedBy.DataValueField = "Practitioner_ID"
                        txtObservedBy.DataTextField = "Practitioner_Name"
                        txtObservedBy.DataBind()
                    End If

            End Select

        End If

 

This is the error I get:
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

Should I use a sqldatasource like you and not try and do it from code behind.

Appreciating your help

Andy

0
Accepted
Tsvetoslav
Telerik team
answered on 06 Apr 2009, 02:46 PM
Hello Andy Green,

Please, note that you should not call the combo's DataBind() method in the ItemCreated event, just remove: txtCompleteBy.DataBind() from your code and everything should work fine. The combo will be automatically bound.

Do let us know if the problem persists.

Best Regards,
Tsvetoslav
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Andy Green
Top achievements
Rank 2
answered on 07 Apr 2009, 01:57 PM
Thank you, worked fine.

Andy
0
Auk
Top achievements
Rank 1
answered on 15 Jan 2012, 11:25 PM
it can be easily done.

Image 1

Open the "Open Property Builder" and the select the master table... and Select the "columns" from the below list and then in the rigth side add a new dropdown. And then put a nice header and then goto the Data Section and now put as  shown in the image.

image 2 for RadCombo Data Properties in RadGrid / DataFields
Tags
Grid
Asked by
Andy Green
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Andy Green
Top achievements
Rank 2
Tsvetoslav
Telerik team
Shinu
Top achievements
Rank 2
Auk
Top achievements
Rank 1
Share this question
or