Binding C1ComboBox in C1GridView template column

Posted by: timothy1 on 10 September 2017, 11:33 am EST

  • Posted 10 September 2017, 11:33 am EST

    I have a C1GridView in my webform that contains a Template Column containing a C1ComboBox.

    The GridView is bound to the parent table showing what has already been entered by the user.  I want to bind the combobox in the Edit Item Template to the lookup table for which the values for that column may be selected from. 

    The problem occurrs when the user edits a previously entered row.  The C1ComboBox does not have a SelectedValue property to bind the previously entered value to.  I can bind to the Text property of the C1ComboBox but that doesn't help if the value is a Code and the Text property will not Select the item in the Combo.

    How does one Bind the C1GridView to a parent table and a C1ComboBox in an EditItemTempate column to the lookup table for which it's values are associated and Select the correct value in the C1ComboBox on Edit?





  • Replied 10 September 2017, 11:33 am EST


    You need to manually get the value from C1ComboBox and pass it to the grid, something like this:

    protected void C1GridView1_RowUpdating(object sender, C1.Web.UI.Controls.C1GridView.C1GridViewUpdateEventArgs e)


       C1ComboBox combo = (C1ComboBox)C1GridView1.Rows[e.RowIndex].FindControl("C1ComboBox3");

       e.NewValues.Add("SOME_FIELD", combo.SelectedItem.Value);


    It is assumed "SOME_FIELD" exists in UPDATE query.



  • Replied 10 September 2017, 11:33 am EST

    Hello Mita,

    Please find the attached sample, wherein C1GridView is bind to a MasterTable and DropDownList is bound to a lookup table.
    When row is in edit mode, you can select a value from dropdown and then update the grid.

  • Replied 10 September 2017, 11:33 am EST

    Hi Nidhi,

    Oh my goodness! I am so very thankful to you. I had given up on this arnd just created a workaround which is not very graceful but works. I.e., whenever user wants to add a new record, they have to select from a combo box outside of grid. :( But I will certainly try your sample code. FYI, i inserted the combobox inside the edittemplate because I don't want users to see DDList unless they are editing.

    'will look into the code tomorrow.

    Again, much obliged,

  • Replied 10 September 2017, 11:33 am EST

    Hello Mita,

    This is exactly what has been done in this sample. User can see the already selected value when Grid is not in Edit Mode. DropDown is shown only after grid is in edit mode and then user can select the value from it.

    Feel free to revert in case you face any further problems.
  • Replied 10 September 2017, 11:33 am EST

    Thanks so very much Nidhi! You're a lifesaver! Ahh! I spent 3 days trying to make this work and without gold support, it's just hard. I am so glad we have this forum site!

    Best Regards,

  • Replied 10 September 2017, 11:33 am EST

    Hi Nidhi,

    One more quick question. The sample you have already has the datasource in the aspx page. What if I want to bind the dropdown list at run time? I.e., I probably would need to run the c1gridview1_rowdatabound method, right?

    Below is my code that doesn't find the dropdown list control within c1gridview1:

    Private Sub C1GridView1_RowDataBound(ByVal sender As Object, ByVal e As C1.Web.UI.Controls.C1GridView.C1GridViewRowEventArgs) Handles C1GridView1.RowDataBound
    If e.Row.RowType = C1.Web.UI.Controls.C1GridView.C1GridViewRowType.DataRow Then
    If (e.Row.RowState & C1.Web.UI.Controls.C1GridView.C1GridViewRowState.Edit) > 0 Then
    ' here find your dropdownlist by id and set the index
    'Dim editor As TimeSchemeEditor = CType(e.Row.FindControl("timeSchemeEditor"), TimeSchemeEditor)
    'editor.TimeScheme = CType(e.Row.DataItem, ServiceDirectoryRoomTypeItem)
    ' Else

    Dim myTable As DataTable = New DataTable()
    Dim ds As DataSet = New DataSet()
    myTable = GetDataTable()

    Dim ddl As DropDownList = CType(e.Row.FindControl("ddlFactory"), DropDownList)

    If ddl Is Nothing Then
    Exit Sub
    ddl.DataSource = myTable
    ddl.DataTextField = "Factory"
    ddl.DataValueField = "FactoryID"
    End If
    End If
    End If

    End Sub
  • Replied 10 September 2017, 11:33 am EST

    Do you have a sample source code for this? Please help!
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels