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

Setting previous values with Custom Edit Forms using rad combo/text boxes

2 Answers 75 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 22 Jan 2009, 09:08 PM
I have am using a custom edit form to update & insert information in my radgrid which contains 3 radcomboboxes & 1 radtextbox.  Update works great, edit works but it doesn't set the default values of the drop downs to the current values.  I am NOT using auto insert/update/delete.  I can set the text value by doing:
Text='<%# Eval( "Description" ) %>' 

But if I try this with the comboboxes and the "SelectedValue=" I get a "Selection out of range Parameter:value" error.  I am binding my controls from db information in a hooked up RadGrid1_ItemDataBound method.  I'm thinking I have to set the SelectedValue somewhere in this method, after something like:
GridItem gridItem = e.Item as GridItem; 
if (!gridItem.OwnerTableView.IsItemInserted) 

then where do I go from here?  I've spent too long looking through examples and searching this forum, so I apologize if this is easy or should have been easy to find out how.
Thanks.


2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 23 Jan 2009, 06:13 AM
Hello Nick,

You can try out the following code to set the SelectedValue of a ComboBox control in the custom EditFormTemplate of your grid:
aspx:
  <EditFormSettings EditFormType="Template" >  
               <FormTemplate>                   
                   <telerik:RadComboBox ID="RadComboBox" runat="server"
                   </telerik:RadComboBox> 
               </FormTemplate>                
  </EditFormSettings> 

cs:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode && !e.Item.OwnerTableView.IsItemInserted) 
        { 
            GridEditFormItem formItem = (GridEditFormItem)e.Item; 
            RadComboBox dropdown = (RadComboBox)formItem.FindControl("RadComboBox"); 
            dropdown.DataSourceID = "SqlDataSource1"
            dropdown.DataTextField = "Category"
            dropdown.DataValueField = "Category"
            dropdown.SelectedValue = DataBinder.Eval(formItem.DataItem, "Category").ToString(); 
        } 
   } 

Thanks
Princy.
0
Nick
Top achievements
Rank 1
answered on 23 Jan 2009, 04:30 PM
Showed me the right direction to take and it works.  Thanks Princy.
Tags
Grid
Asked by
Nick
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Nick
Top achievements
Rank 1
Share this question
or