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

Edit databound radgrid

4 Answers 93 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Fali
Top achievements
Rank 1
Fali asked on 11 Feb 2014, 04:39 AM
Hi,

I would like to achieve this Grid - Automatic Operations but I don't want to use Item Template. I would like to have the edit options so the data could be edited by user. Please guide. Below are my codes:

1.<telerik:RadGrid ID="dgvSummary" runat="server" AllowPaging="true" AllowSorting="true" CellSpacing="0" PageSize="7"  Skin="Hay" Width="100%" GridLines="None">
2.          <MasterTableView />
3.</telerik:RadGrid>
01.Private Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
02.        Me.dgvSummary.DataSource = Me._PopulatedgvSummary()
03. 
04.        If Me.dgvSummary.DataSource IsNot Nothing Then
05.            Me.dgvSummary.DataBind()
06.            Me.pnlSummary.Visible = True
07.        Else
08.            Me.pnlSummary.Visible = False
09.        End If
10.    End Sub

01.Private Function _PopulatedgvSummary()
02.        Dim tblData As DataTable = Me._GenerateTableShema
03.        Dim intIndex As Integer = 1
04.        Dim strEdit As String = String.Empty
05. 
06.        For Each objView_EvalSummaryRow As DSHREval.HREvalRow In HREvalDALC.GetEvalSummary(Me.radDepartment.SelectedValue, Me.radPosition.SelectedValue, Me.txtStarYear.Text, Me.cboStarTerm.SelectedValue)
07. 
08.            strEdit = "<a id=""popup"" href=""" & SharedCommon.GenerateLink(Request, SharedCommon.EditEvaSummary) & "?" & SharedCommon.ID & "=" & objView_EvalSummaryRow.ID.ToString & """>" & "Edit" & "</a>"
09.            tblData.Rows.Add(New Object() {intIndex, objView_EvalSummaryRow.EmpID, objView_EvalSummaryRow.EmpName, objView_EvalSummaryRow.PropertyCode, _
10.                                           objView_EvalSummaryRow.Department, objView_EvalSummaryRow.PresentPosition, _
11.                                           objView_EvalSummaryRow.Average, objView_EvalSummaryRow.FinalAverage, strEdit})
12. 
13.            intIndex += 1
14.        Next
15. 
16.        If tblData.Rows.Count = 0 Then
17.            tblData = Nothing
18.        End If
19. 
20.        Return tblData
21.    End Function

01.Private Function _GenerateTableShema() As DataTable
02.        Dim tblData As New DataTable
03. 
04.        With tblData.Columns
05.            .Add("Num.")
06.            .Add("Staff ID")
07.            .Add("Name")
08.            .Add("Property")
09.            .Add("Department")
10.            .Add("Position")
11.            .Add("Average Mark")
12.            .Add("Final Mark")
13.            .Add(" ")
14.        End With
15. 
16.        Return tblData
17.    End Function

Thank you in advance

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 11 Feb 2014, 05:25 AM
Hi Fali,

I'm not clear about your requirement. I guess you want to edit the rows of the Radgrid, you can set AutoGenerateEditColumn="true" for the RadGrid to have the edit column.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateEditColumn="true". .>

Thanks,
Princy

0
Fali
Top achievements
Rank 1
answered on 11 Feb 2014, 06:36 AM
Yes Princy,

That's what I want but when the grid is generated and clicking the edit button makes my grid disappear. I think its because I'm binding datatable to the radgrid. And I have no idea to make it work.
0
Fali
Top achievements
Rank 1
answered on 11 Feb 2014, 08:51 AM
Now here is my codes:

<telerik:RadAjaxPanel ID="radSummary" runat="server" Height="200px" Width="100%">
          <telerik:RadGrid ID="dgvSummary" runat="server" AllowPaging="true" AllowSorting="true" CellSpacing="0" PageSize="7" Skin="Hay" Width="100%" GridLines="None" AutoGenerateEditColumn="true" OnNeedDataSource="dgvSummary_NeedDataSource" OnUpdateCommand="dgvSummary_UpdateCommand">
                    <MasterTableView EditMode="InPlace" />
          </telerik:RadGrid>
</telerik:RadAjaxPanel>

Protected Sub dgvSummary2_NeedDataSource(ByVal source As Object, ByVal e As GridNeedDataSourceEventArgs) Handles dgvSummary2.NeedDataSource
          Me.dgvSummary.DataSource = Me._PopulatedgvSummary()
 End Sub

There is a update button but I'm stuck how I can update it. How can I get the unique id from the row being edited and update?
0
Princy
Top achievements
Rank 2
answered on 12 Feb 2014, 05:05 AM
Hi Fali,

Please try the following code snippet to access the values on Update and use NeedDataSource event to bind the RadGrid

VB:
Protected Sub dgvSummary_UpdateCommand(sender As Object, e As GridCommandEventArgs)
    Dim edit As GridEditableItem = DirectCast(e.Item, GridEditableItem)
    Dim newValues As New Hashtable()
    e.Item.OwnerTableView.ExtractValuesFromItem(newValues, edit)
    Dim num As String = newValues("Num").ToString()
    Dim staffId As String = newValues("Staff ID").ToString()
    'Similary access all the values
    'Code to Update
End Sub

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