locked
RADGRID - ADDING CONTROLS DYNAMICALLY AND RETRIEVING VALUES FROM THE CONTROLS RRS feed

  • Question

  • User1972565377 posted

    I am using RadGrid Control.

    I have created the columns for RadGrid dynamically with two textbox, one dropdown and 1 date picker.

    I have created controls dynamically using GridTemplateColumn by assigning UniqueName for ItemTemplate, getting ID for each control(TextBox, Dropdown, DatePicker).

    User Inputs the value in dynamically created grid.

    While clicking on Save button, the value from each row of the grid should be retrieved. But I am not able to retrieve the values since I created the grid with controls dynamically.

    Thursday, September 14, 2017 4:24 PM

All replies

  • User-2010311731 posted

    Please post your code that creates the controls and also the save.

    Thursday, September 14, 2017 4:53 PM
  • User1972565377 posted

    Will provide few lines for getting the textbox value

    Here TxtBox itself gives "Nothing"

    For each item as GridDataItem In RadGrid.MasterTableView.Items

            DIm TxtBox AS RadTextBox = TryCast(item("UniqueNameOfTemplateColumn").FindControl("txtBoxID"))

            Dim Val As String = TxtBox.Text

    Next

    Thursday, September 14, 2017 4:58 PM
  • User1972565377 posted

    Hi Have two buttons

    One is "Create Grid" and another is "Save"

    Once I click on "Create Grid" button the grid generate with dynamic textbox, date picker, drop down column which uses telerik controls.


    Private Class MyTemplate
        Implements ITemplate
        Protected textBox As TextBox
        Private colname As String
        Public Sub New(cName As String)
            colname = cName
        End Sub
        Public Sub InstantiateIn(container As System.Web.UI.Control)
            Dim textBox as New RadTextBox()
            textBox.ID = "TextBox1"
            container.Controls.Add(textBox)
        End Sub
    End Class

    Protected Sub Button1_Click(sender As Object, e As EventArgs)
       Dim TemplateCol As GridTemplateColumn()

      TemplateCol.Itemtemplate = New MyTemplate("Name")

      TemplateCol.UniqueName = "Name"

      TemplateCol.HeaderText = "Name"

    RadGrid.MasterTableView.Columns.Add(TemplateCol)


    End Sub

     When I click on "Save" button below code performs

    For each item as GridDataItem In RadGrid.MasterTableView.Items

            DIm TxtBox AS RadTextBox = TryCast(item("Name").FindControl("TextBox1"))

            Dim Val As String = TxtBox.Text

    Next

    Thursday, September 14, 2017 5:08 PM
  • User-2010311731 posted

    You can try changing the TryCast to DirectCast to see an error message that might point you in the right direction.

    Thursday, September 14, 2017 5:12 PM
  • User1972565377 posted

    DirectCast also not working. It also does not produce value given in radtextbox.

    Thursday, September 14, 2017 5:15 PM
  • User1972565377 posted

    Please let me know the way to retrieve the values from dynamically created textbox, datepicker, dropdown inside radgrid.

    Thursday, September 14, 2017 5:16 PM
  • User1972565377 posted

    Is there any way to get the value given in textbox from the item.ClientID?

    Thursday, September 14, 2017 5:18 PM