I'm pretty new to Telerik and was undering if anyone could help. Apologies if this post is in the wrong forum.
I have a RadGrid which contains several RadComboBoxes one of which enables or disables other TextBox controls on the grid at edit. When I add a new row to the RadGrid and select an entry from the ComboBox it correctly disables/enables the TextBoxes on the data entry form. When I return to the same record in the RadGrid to update the entry the TextBoxes are all enabled. Where should I be setting the TextBox state? I've tried to do this in ItemDataBound and ItemCreated.
The other issue can wait until I've got my head around this one.
Thanks for your time.
4 Answers, 1 is accepted
How are you handling the enabling/disabling of the textboxes at present? When you alter the selection in the combobox, and alter the enabled state of the textbox, is this state preserved somewhere?
Additionally, you can use the ItemDataBound event handler, to get a reference to the edit form, and pre-set the enabled property of the textboxes, for example depending on the current selection in the combo. Is this the behavior which you are after, or perhaps I am leaving something out.
Sincerely yours,
Yavor
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
I think first I'll give you the description of what I'm trying to do then what I'm doing in code....
I have a dropdown in the edit form. Depending on what is selected in the this dropdown I have another dropdown that may or may not be required. If it is then I go off and load the selected for the new dropdown and need to change the lable of this dropdown at the same time as each entry in the first dropdown loads different 'types' of data in t the second one.
For example - In the first dropdown I have 2 entries:
Home and Car, if Home is selected the second dropdown is made visible and populated with a list of postcodes and the lable associated with this is Postcode. If Car is selected then the second dropdown is populated with Registrations and the lable or HeaderText is set to Reg.
I'm attempting to do this in a function I'm setting up with:
Dim
TypeList As RadComboBox = CType(CType(e.Item, GridEditableItem)("Type").Controls(0), RadComboBox)
TypeList.AutoPostBack =
True
AddHandler TypeList.SelectedIndexChanged, AddressOf Me.Typelist_SelectedIndexChanged
Which is in the ItemCreated method.
When the TypeList combo is changed I try to do this in Typelist_SelectedIndexChanged:
Dim
editedItem As GridEditableItem = CType(CType(sender, RadComboBox).NamingContainer, GridEditableItem)
Dim
ddType As RadComboBox = CType(editedItem("Type").Controls(0), RadComboBox)
QuestionID = ddType.SelectedValue
editedItem(
"Question1DDL").Visible = True
editedItem(
"Question1DDL").Enabled = True
RadGridClaims.Columns.FindByUniqueName(
"Question1DDL").Visible = True
RadGridClaims.Columns.FindByUniqueName(
"Question1DDL").Display = True
RadGridClaims.Columns.FindByUniqueName(
"Question1DDL").EditFormHeaderTextFormat = QuestionLable
Dim
editMan As GridEditManager = editedItem.EditManager
Dim editor As GridDropDownColumnEditor = CType(editMan.GetColumnEditor("Question1DDL"), GridDropDownColumnEditor)
DropdownTable = AddDataSource(QuestionID)
editor.DataSource = DropdownTable
editor.DataBind()
The code seems to run ok but the new lable next to the new Question1DDL dropdown is blank so the data on the form is ambiguous.
I also do something very similar in ItemDataBound - trying to set visibility and header text there too but no luck.
Hope this is of some use as this problem is sending me nuts!
All the best,
Nik
I tried to implement a similar scenario on my end and I am able to modify the label text that appears in the EditForm on changing the selection of the first ComboBox as shown below.
CS:
| <telerik:GridDropDownColumn UniqueName="DropCol1" DataSourceID="SqlDataSource1" DropDownControlType="RadComboBox" HeaderText="DropCol1" DataField="ProductName" ListTextField="ProductName" ListValueField="ProductName" ></telerik:GridDropDownColumn> |
| <telerik:GridDropDownColumn UniqueName="DropCol2" DataSourceID="SqlDataSource1" DropDownControlType="RadComboBox" HeaderText="DropCol2" DataField="ProductID" ListTextField="ProductID" ListValueField="ProductID" ></telerik:GridDropDownColumn> |
VB:
| Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As GridItemEventArgs) |
| If (TypeOf e.Item Is GridEditableItem) AndAlso (e.Item.IsInEditMode) Then |
| Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem) |
| Dim combo1 As RadComboBox = DirectCast(item("DropCol1").Controls(0), RadComboBox) |
| combo1.AutoPostBack = True |
| AddHandler combo1.SelectedIndexChanged, AddressOf combo1_SelectedIndexChanged |
| End If |
| End Sub |
| Private Sub combo1_SelectedIndexChanged(ByVal o As Object, ByVal e As RadComboBoxSelectedIndexChangedEventArgs) |
| Dim combo1 As RadComboBox = DirectCast(o, RadComboBox) |
| Dim editItem As GridEditableItem = DirectCast(combo1.NamingContainer, GridEditableItem) |
| Dim combo2 As RadComboBox = DirectCast(editItem("DropCol2").Controls(0), RadComboBox) |
| 'popualte the combo2 here |
| 'code to change the label text tht appears in the edit form |
| DirectCast((editItem("DropCol2").Parent), System.Web.UI.WebControls.TableRow).Cells(0).Text = combo1.SelectedItem.Text |
| End Sub |
Thanks
Shinu
Thanks for the reply - this really helped.
I've got the visiblity and correct text showing now.
All the best,
Nik