RadCombo in grid editform

11 posts, 2 answers
  1. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 31 Mar 2009 Link to this post

    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

     

  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 31 Mar 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 01 Apr 2009 Link to this post

    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
  5. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 02 Apr 2009 Link to this post

    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.
  6. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 02 Apr 2009 Link to this post

    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
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 03 Apr 2009 Link to this post

    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
  8. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 03 Apr 2009 Link to this post

    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.
  9. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 04 Apr 2009 Link to this post

    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

  10. Answer
    Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 06 Apr 2009 Link to this post

    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.
  11. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 07 Apr 2009 Link to this post

    Thank you, worked fine.

    Andy
  12. Auk
    Auk avatar
    1 posts
    Member since:
    Jan 2012

    Posted 15 Jan 2012 Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017