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

Grid And ComboBox

4 Answers 46 Views
Grid
This is a migrated thread and some comments may be shown as answers.
pedrotti
Top achievements
Rank 1
pedrotti asked on 22 Nov 2012, 02:41 PM
Hello

Can you help me ?!

I've a grid with a textbox and  a combobox
With editing  (InPlace), i want to rebind the combox with new data depending on textbox value

<Grid......

1er Column
<telerik:GridTemplateColumn UniqueName="Dep" DataField="Dep" HeaderText="Dept" AllowFiltering="false">                          
      <ItemTemplate>
              <%# DataBinder.Eval(Container.DataItem, "Dep")%>

                          </ItemTemplate>
                                    <EditItemTemplate>
                                              <telerik:RadNumericTextBox ID="ntbDept" DataType="System.Integer" runat="server" Width="100%" AutoPostBack="true" ></telerik:RadNumericTextBox>
                                    </EditItemTemplate>                                                                        
                                                
/telerik:GridTemplateColumn>

2 Colum

<telerik:GridTemplateColumn UniqueName="NomCommune" DataField="NomComInsee" HeaderText="Commune" AllowFiltering="false">                          
    <ItemTemplate>
             <%# DataBinder.Eval(Container.DataItem, "NomComInsee")%>
    </ItemTemplate>
                                                    
     <EditItemTemplate>
    
                   <telerik:RadComboBox ID="cbCommune" runat="server" Width="90%" DropDownWidth="400" MarkFirstMatch="True" Filter="StartsWith">  </telerik:RadComboBox>
       </EditItemTemplate>     
       <HeaderStyle Width="40%" />
       </telerik:GridTemplateColumn>


And the code behind
On my grid  ItemDataBound ....

dim dt as new datatable
...fill dt with sqladpter (depending on NomCommune) .... That OK

 Dim cbCommune As RadComboBox = DirectCast(item.FindControl("cbCommune"), RadComboBox)
 cbCommune.DataSource = dt
 cbCommune.DataValueField = "CInsee"
 cbCommune.DataTextField = "NomCom"
 cbCommune.DataBind()

cbCommune is OK but the combobox in the grid  is not updated


PLEASE  HELP ME

Thank a lot

Anne





4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 23 Nov 2012, 04:44 AM
Hi,

I guess you want to show the selected value in the RadComboBox in Edit mode. Please check the following code snippet I tried.

VB:
C#:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs)
    If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then
        Dim edit As GridEditableItem = DirectCast(e.Item, GridEditableItem)
        Dim combo As RadComboBox = DirectCast(edit.FindControl("cbCommune"), RadComboBox)
        combo.DataSource = dt
        combo.DataTextField = "NomCom"
        combo.DataValueField = "CInsee"
        combo.DataBind()
            ' to show the selected text in edit mode
        combo.SelectedItem.Text = DirectCast(DataBinder.Eval(e.Item.DataItem, "NomCom").ToString(), String)
    End If
End Sub

Thanks,
Shinu.
0
pedrotti
Top achievements
Rank 1
answered on 26 Nov 2012, 09:07 AM
Hi,

I get this error message at run :

DataBinding
: 'System.Data.DataRowView' does not contain a property called 'NomCom'



I want to dynamically load the combobox above when the user change the value of the RadNumericTextBox.

The behavior I expect is that, when the user change the value of the NumericTextBox, I call a SQL query which takes the valued the user just changed as parameter. Then I give the DataTable returned as DataSource for this combobox.

Best regards,

Anne

0
Accepted
Shinu
Top achievements
Rank 1
answered on 26 Nov 2012, 09:58 AM
Hi,

One suggestion is that you can populate the combobox in TextChanged event as shown below.
aspx:
<telerik:GridTemplateColumn>
 <EditItemTemplate>
  <telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server" ontextchanged="RadNumericTextBox1_TextChanged"></telerik:RadNumericTextBox>
  <telerik:RadComboBox ID="RadComboBox1" runat="server"></telerik:RadComboBox>
 </EditItemTemplate>
</telerik:GridTemplateColumn>
C#:
protected void RadNumericTextBox1_TextChanged(object sender, EventArgs e)
{
    RadNumericTextBox txt = (RadNumericTextBox)sender;
    GridEditableItem item = (GridEditableItem)txt.NamingContainer;
    RadComboBox combo = (RadComboBox)item.FindControl("RadComboBox1");
    //populate the combobox here
}

Thanks,
Shinu.
0
pedrotti
Top achievements
Rank 1
answered on 26 Nov 2012, 12:42 PM
It works very well !

Thank you for your help :)
Tags
Grid
Asked by
pedrotti
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
pedrotti
Top achievements
Rank 1
Share this question
or