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

Is is possible to save both the Text and Value to separate database fields using a GridDropDownColumn?

3 Answers 44 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 23 May 2012, 04:39 PM
I have grid that contains a GridDropDownColumn (data from a different table).  This uses a different value in the ListValueField than it does in the ListTextField.  The reason is because I need a less descriptive value for use as a QueryString later on.  I need to keep the descriptive text as well on the database for the record.  How can I save both values in my database using the single GridDropDownColumn?  Do I need to use code behind?  If so, what event needs to be used?

Thanks!

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 28 May 2012, 12:39 PM
Hi Mark,

You could access the updated Text and Value of the GridDropDownColumn using the OnItemCommand server side event and overwrite your database accordingly:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.PerformInsertCommandName || e.CommandName == RadGrid.UpdateCommandName)
        {
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)
            {
                GridEditableItem editItem = e.Item as GridEditableItem;
                RadComboBox cmbBox = editItem["ColumnUniqueName"].Controls[0] as RadComboBox;
 
                string updatedText = cmbBox.SelectedItem.Text;
                string updatedValue = cmbBox.SelectedValue;
            }
        }
    }

Please check out the following article where GridDropDownColumn's specifications are described:
  Configure GridDropDownColumn

If you have further requirements, please elaborate some more on the issue. It would be best if you open a support ticket and send us your mark-up and the related code-behind. Thus, we will be able to further analyze the project and provide a proper approach.

Regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Mark
Top achievements
Rank 1
answered on 02 Jun 2012, 11:08 AM
Ok.  Thank you very much, that worked perfectly.  Now, how would you go about placing the value of the selected item into another textbox on the grid as soon as the combobox has been used?  This is proving much more difficult than expected.
0
Princy
Top achievements
Rank 2
answered on 04 Jun 2012, 05:10 AM
Hi Mark,

With reference to this documentation, when using DropDownColumn in Edit mode, you can save the selected value in a Session variable and then set that value for the label in ItemTemplate.Here is the sample code.
C#:
void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
 if (e.Item is GridEditableItem && e.Item.IsInEditMode)
 {
   GridEditableItem item = (GridEditableItem)e.Item;
   RadComboBox combo = (RadComboBox)item["GridDropDownColumn"].Controls[0];
  //populating the combobox
   if (Session["updatedValue"] != null)
    {
       combo.SelectedValue = Session["updatedValue"].ToString();
    }
 }
   if (e.Item is GridDataItem && !e.Item.IsInEditMode && Page.IsPostBack)
    {
      GridDataItem item = e.Item as GridDataItem;
      TextBox txt = (TextBox)item.FindControl("TextBox1");
      txt.Text = Session["updatedValue"].ToString();
    }
}

Thanks,
Princy.
Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Mark
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or