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

I want create bulk editing RadGrid please help me.

2 Answers 105 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jadesada
Top achievements
Rank 1
Jadesada asked on 18 Oct 2011, 08:28 AM
I want to create a RadGrid bulk editing by code behide. In GridDataItem have TextBox to show data in my datasource and it's can change data in textbox. Then after I press button save it's will read every data in TextBox in RadGrid and save changed data to datasource.

I will try to make my program like this by using GridTemplateColumn (in programmatic) I can bind data to textbox in TemplateColumn but when I press save button.... Textbox in RadGrid are disappear o_O!!. I don't know what's going on. Please help me I'm so tried to fine solution :'(

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 18 Oct 2011, 10:50 AM
Hello Jadesada,

Your scenario should work normally. Please make sure that You have defined the Grid structure in PageInit and grid columns should be added to the Columns collection of the MasterTableView after their attributes are set.

You can check the following documentation for more on this.
Programmatic Creation

Hope it helps.

Thanks,
Princy.
0
Jadesada
Top achievements
Rank 1
answered on 18 Oct 2011, 11:46 AM
Hello Princy.

Now, I can insert textbox into RadGrid by this code.

Partial Class Default2
    Inherits System.Web.UI.Page
 
    Dim oConnector As Connector
 
    Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
        DefineStructure()
        MyBase.OnInit(e)
    End Sub
 
    Private Sub DefineStructure()
 
        Dim cCompanyID As New GridTemplateColumn
        Me.RadGrid1.MasterTableView.Columns.Add(cCompanyID)
        With cCompanyID
            .HeaderText = "รหัสองค์กร"
            .DataField = "companyID"
            .ItemTemplate = New MyTemplate("companyID")
            .UniqueName = "column1"
        End With
 
        Dim cCompanyName As New GridTemplateColumn
        Me.RadGrid1.MasterTableView.Columns.Add(cCompanyName)
        With cCompanyName
            .HeaderText = "ชื่อองค์กร"
            .DataField = "companyname"
            .ItemTemplate = New MyTemplate("companyname")
            .UniqueName = "column2"
        End With
    End Sub
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        oConnector = New Connector
 
        If Not IsPostBack Then
            ViewState("data") = oConnector.ExecuteQuery("select companyID, comparnyName, address1, address2 from company")
        End If
 
        RadGrid1.DataSource = ViewState("data")
        RadGrid1.DataBind()
 
        RadAjaxLoadingPanel1.Transparency = 30
        RadAjaxManager1.DefaultLoadingPanelID = RadAjaxLoadingPanel1.ID
        RadAjaxManager1.AjaxSettings.AddAjaxSetting(Button1, RadGrid1)
    End Sub
 
    Protected Sub RadGrid1_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
        'RadGrid1.DataSource = ViewState("data")
    End Sub
 
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        For Each dItem As GridDataItem In RadGrid1.Items
            Dim wx As String = dItem("column1").Text
        Next
    End Sub
 
    Private Class MyTemplate
        Implements ITemplate
 
        Protected lControl As LiteralControl
        Protected validatorTextBox As RequiredFieldValidator
        Protected textBox As TextBox
        Private colname As String
 
        Public Sub New(ByVal cName As String)
            MyBase.New()
            colname = cName
        End Sub
 
        Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements ITemplate.InstantiateIn
            textBox = New TextBox
            textBox.ID = "templateColumnTextBox" & colname
            AddHandler textBox.DataBinding, AddressOf Me.textbox_DataBinding
            'validatorTextBox = New RequiredFieldValidator
            'validatorTextBox.ControlToValidate = "templateColumnTextBox"
            'validatorTextBox.ErrorMessage = "*"
            'Dim table As Table = New Table
            container.Controls.Add(textBox)
        End Sub
 
        Private Sub textbox_DataBinding(ByVal sender As Object, ByVal e As EventArgs)
            Dim tb As TextBox = CType(sender, TextBox)
            Dim container As GridDataItem = CType(tb.NamingContainer, GridDataItem)
            tb.Text = CType(container.DataItem, DataRowView)(colname).ToString
        End Sub
    End Class
End Class

On this code my TextBox control in RadGrid will appear when I click save button.
But...my next problem is when I click save button and page is postback. This RadGrid will create column again depend on this picture I don't know what happen on this page. Please help me.



Thanks, 
Jadesada.
Tags
Grid
Asked by
Jadesada
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jadesada
Top achievements
Rank 1
Share this question
or