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

Grid combobox in edit mode

4 Answers 325 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Acadia
Top achievements
Rank 1
Iron
Acadia asked on 20 Aug 2008, 08:49 PM
I've tried to figure this out but this one piece is stumping me.  I'm sure it's easy for one of the more experienced rad users or Telerk, but I'm not seeing it.

I have a Rad Grid for Ajax with a textbox column that when in edit mode is a Rad Combobox.  When I switch to edit mode I want the combobox to be set to the value of the textbox.  The combobox is populated on demand in edit mode, which might be the problem, but I don't know how else to populate the combobox when I enter edit mode.

Is there a way to retrieve the original value of the textbox in the following method and set the combo to that after I populate the combo?

Public

Sub rcLt_ItemsRequested(ByVal sender As Object, ByVal e As RadComboBoxItemsRequestedEventArgs)

Dim itemsList As String() = {"J", "G"}

Dim comboBox As RadComboBox = DirectCast(sender, RadComboBox)

comboBox.Items.Clear()

comboBox.DataSource = itemsList

comboBox.DataBind()

'How do I retrieve the value of the textbox from before I entered edit mode?

End Sub

If somebody could give me some guidanc on this that would be great!

Thanks

4 Answers, 1 is accepted

Sort by
0
Acadia
Top achievements
Rank 1
Iron
answered on 21 Aug 2008, 05:36 PM
I changed my code to populate the combobox in the item databound, but I still don't see how to access the value of the non-editable item when I am in edit mode.

I want to set my edit mode combo to the value of the non-edit mode textbox from that sme row.  How does telerik recommend doing this server-side when entering edit mode and in which method would you recommend?  I've tried everything - ItemDataBound and ItemCommand of the grid and the problem seems to be that you cannot simultaneously access the non-editable column and the editable column.  It's one or the other.

Here is my grid column:

<telerik:GridTemplateColumn DataField="LINE_TYPE" HeaderText="Line Type" UniqueName="LINE_TYPE">

<HeaderStyle HorizontalAlign="Left" Width="60px" Wrap="False" />

<ItemStyle HorizontalAlign="Left" Width="60px" Wrap="False" />

<ItemTemplate>

<asp:Label runat="server" ID="lblLineType" CssClass="Normal" Width="60px" Text='<%#DataBinder.Eval(Container, "DataItem.LINE_TYPE") %>'></asp:Label>

</ItemTemplate>

<EditItemTemplate>

<telerik:RadComboBox ID="rcLt" runat="server" Skin="WebBlue" AutoPostBack="True"

OnItemsRequested="rcLt_ItemsRequested" EnableLoadOnDemand="True" Width="40px"

AllowCustomText="false" >

</telerik:RadComboBox>

</EditItemTemplate>

</telerik:GridTemplateColumn>


I'll keep plugging away but some guidance would be helpful.

Thanks

0
Shinu
Top achievements
Rank 2
answered on 22 Aug 2008, 06:33 AM
Hi Acadia,

Try the following code snippet to achieve the desired scenario.

ASPX:
<telerik:GridTemplateColumn UniqueName="TempCol"  DataField="ImageField"  HeaderText="TempCol"  > 
                     <ItemTemplate> 
                         <asp:TextBox ID="TextBox1" runat="server" Text='<%#Eval("FirstName") %>'></asp:TextBox> 
                     </ItemTemplate> 
                     <EditItemTemplate> 
                         <telerik:RadComboBox ID="RadComboBox2" runat="server" DataSourceID="SqlDataSource1" DataTextField="FirstName"
                         </telerik:RadComboBox> 
                     </EditItemTemplate> 
                    </telerik:GridTemplateColumn> 


CS:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode)) 
        { 
            GridEditFormItem edititem = (GridEditFormItem)e.Item; 
            GridDataItem dataItem = (GridDataItem)edititem.ParentItem; 
            TextBox txtbx = (TextBox)dataItem["TempCol"].FindControl("TextBox1"); 
            RadComboBox combo = (RadComboBox)edititem["TempCol"].FindControl("RadComboBox2"); 
            combo.SelectedValue = txtbx.Text; 
        } 
        
    } 


Thanks
Shinu.
0
Acadia
Top achievements
Rank 1
Iron
answered on 22 Aug 2008, 12:24 PM
Thanks for the suggestion, but unfortunately this doesn't work.  The code is never hit at any time in the itemdatabound event.
0
Acadia
Top achievements
Rank 1
Iron
answered on 22 Aug 2008, 01:50 PM
I solved it.  I just typed the entire solution and hit replay a minute ago and somehow my post got lost - so sorry but I'm not doing that again I don't have time.

The bottom line is I ended up adding an invisible label as another control in the edit template and just referred to that in the itemdatabound event of my grid.  By doing so I was able to access both the editable combo and the invisible control and set the combo to the original value of the invisible control (which is data bound to the same field as the non-editable label.

Works perfectly so far.

Thanks to everyone for their input and if anybody actually needs the detailed code just replay to this thread and I'll post it.
Tags
Grid
Asked by
Acadia
Top achievements
Rank 1
Iron
Answers by
Acadia
Top achievements
Rank 1
Iron
Shinu
Top achievements
Rank 2
Share this question
or