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

RadGrid updating but not in my database table help plss

2 Answers 47 Views
Grid
This is a migrated thread and some comments may be shown as answers.
robin
Top achievements
Rank 1
robin asked on 25 Jul 2010, 11:48 AM
This code is loosely based on several of the demos. My main problem here is that when i run my program and happen to see my gridview the datas are not the same as with my datas in my table in my database.

And when i tried to hit the edit button.. and make some few changes.. it updates my gridview but not the same as my datas in my table in my database..

hope someone could lend a helping hand..

here's my code.. by the way i'm just a newbie in asp.net ..please be gentle.. thanks

ASPX

<%@ Page Language="VB" MasterPageFile="~/Admin/Admin.master" AutoEventWireup="false" CodeFile="TeacherRole.aspx.vb" Inherits="Admin_TeacherRole" title="Untitled Page" %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
     
  
<html>
 
<body>
       <!-- content start -->
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
 
        <script type="text/javascript">
            function RowDblClick(sender, eventArgs) {
                sender.get_masterTableView().editItem(eventArgs.get_itemIndexHierarchical());
            }
        </script>
 
    </telerik:RadCodeBlock>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" 
        DefaultLoadingPanelID="RadAjaxLoadingPanel1">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
 
       <telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True"
            AllowPaging="True" AllowSorting="True" OnUpdateCommand = "RadGrid1_UpdateCommand"
            AutoGenerateEditColumn="True"  GridLines="None"
            Skin="Black"
        AllowAutomaticUpdates="True" ShowGroupPanel="True" GroupPanel-ID = "RadAjaxLoadingPanel1">
         
             <MasterTableView EditMode="PopUp" AutoGenerateColumns="False"  DataKeyNames = "user_id"
                CommandItemDisplay="Top">
                 
                <Columns>
                     <telerik:GridBoundColumn DataField="user_id" DataType="System.Int32"
                        HeaderText="User ID" SortExpression="user_id" UniqueName="user_id" ReadOnly="True">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="lastname" HeaderText="Last Name"
                        SortExpression="lastname" UniqueName="lastname" ReadOnly="False">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="firstname" HeaderText="First Name"
                        SortExpression="firstname" UniqueName="firstname" ReadOnly="False">
                    </telerik:GridBoundColumn>
 
                </Columns>
                 
                <EditFormSettings CaptionFormatString="Edit User ID: {0}"  CaptionDataField="user_id" PopUpSettings-Modal="True" PopUpSettings-ScrollBars="Auto"
                EditFormType= "AutoGenerated">
                    <FormTableItemStyle Width="100%" Height="29px"></FormTableItemStyle>
                    <FormTableStyle GridLines="None" CellSpacing="0" CellPadding="2"></FormTableStyle>
                    <FormStyle Width="100%" BackColor="#eef2ea"></FormStyle>
                    <EditColumn ButtonType="PushButton" />
                     
<PopUpSettings ScrollBars="Auto" Modal="True"></PopUpSettings>
                </EditFormSettings>
            </MasterTableView>
             <ClientSettings AllowDragToGroup="True">
                <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                <ClientEvents OnRowDblClick="RowDblClick" />
            </ClientSettings>
        </telerik:RadGrid>
   
    
    <!-- content end -->
 
</body>
</html>
</asp:Content>


VB
Imports System
Imports System.Configuration
Imports System.Data
Imports System.Data.Common
Imports System.Data.SqlClient
Imports System.Globalization
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports Telerik.Web.UI
 
Partial Class Admin_TeacherRole
    Inherits System.Web.UI.Page
 
    Private Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid1.PreRender
        If Not IsPostBack Then
            For Each item As GridItem In RadGrid1.MasterTableView.Items
                If TypeOf item Is GridEditableItem Then
                    Dim editableItem As GridEditableItem = CType(item, GridDataItem)
                    editableItem.Edit = True
                End If
            Next
            RadGrid1.Rebind()
        End If
    End Sub
    Private Sub Page_PreRender(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
        If Not MyBase.IsPostBack Then
            Me.RadGrid1.MasterTableView.Items(0).Edit = True
            Me.RadGrid1.MasterTableView.Rebind()
        End If
    End Sub
    Public ReadOnly Property UserData() As DataSet
        Get
            Dim obj As Object = Me.Session("UserData")
            If Not obj Is Nothing Then
                Return CType(obj, DataSet)
            End If
 
            Dim MyUserData As DataSet = New DataSet
 
            Dim ConnString As String = ConfigurationManager.ConnectionStrings("ProLearnConnectionString").ConnectionString
            Dim conn As SqlConnection = New SqlConnection(ConnString)
            Dim adapter As SqlDataAdapter = New SqlDataAdapter
            adapter.SelectCommand = New SqlCommand("SELECT user_id, lastname, firstname FROM tblStudents ORDER BY user_id", conn)
 
            adapter.Fill(MyUserData, "tblStudents")
 
            Me.Session("UserData") = MyUserData
 
            Return MyUserData
        End Get
    End Property
    Private Sub RadGrid1_NeedDataSource(ByVal source As System.Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
        RadGrid1.DataSource = Me.UserData
        Me.UserData.Tables("tblStudents").PrimaryKey = New DataColumn() {Me.UserData.Tables("tblStudents").Columns("user_id")}
    End Sub
    Protected Sub RadGrid1_UpdateCommand(ByVal source As System.Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.UpdateCommand
 
        Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
        Dim editMan As GridEditManager = editedItem.EditManager
 
        Dim column As GridColumn
 
        For Each column In e.Item.OwnerTableView.Columns
            If TypeOf column Is IGridEditableColumn Then
                Dim editableCol As IGridEditableColumn = CType(column, IGridEditableColumn)
                If (editableCol.IsEditable) Then
                    Dim editor As IGridColumnEditor = editMan.GetColumnEditor(editableCol)
 
                    Dim editorType As String = CType(editor, Object).ToString()
                    Dim editorText As String = "unknown"
                    Dim editorValue As Object = Nothing
 
                    If (TypeOf editor Is GridTextColumnEditor) Then
                        editorText = CType(editor, GridTextColumnEditor).Text
                        editorValue = CType(editor, GridTextColumnEditor).Text
                    End If
 
                    If (TypeOf editor Is GridBoolColumnEditor) Then
                        editorText = CType(editor, GridBoolColumnEditor).Value.ToString()
                        editorValue = CType(editor, GridBoolColumnEditor).Value
                    End If
 
                    If (TypeOf editor Is GridDropDownColumnEditor) Then
                        editorText = CType(editor, GridDropDownColumnEditor).SelectedText & "; " & CType(editor, GridDropDownColumnEditor).SelectedValue
                        editorValue = CType(editor, GridDropDownColumnEditor).SelectedValue
                    End If
 
                    Try
                        Dim changedRows As DataRow() = Me.UserData.Tables("tblStudents").Select("user_id = " & editedItem.OwnerTableView.DataKeyValues(editedItem.ItemIndex)("user_id"))
                        changedRows(0)(column.UniqueName) = editorValue
                        Me.UserData.Tables("tblStudents").AcceptChanges()
 
                    Catch ex As Exception
                        RadGrid1.Controls.Add(New LiteralControl("<strong>Unable to set value of column '" & column.UniqueName & "'</strong> - " + ex.Message))
                        e.Canceled = True
                    End Try
 
                End If
            End If
        Next
 
 
    End Sub
 
End Class

2 Answers, 1 is accepted

Sort by
0
robin
Top achievements
Rank 1
answered on 27 Jul 2010, 02:24 AM
Any help? please -_-
0
Radoslav
Telerik team
answered on 29 Jul 2010, 07:39 AM
Hi Robin,

I examined the code you post and it is looks correct, however it is not runnable and I could not reproduce the described issue. Could you please send us a simple runnable project that could be used for reproducing the problem. You could open a formal support ticket from your Telerik account and attach a ZIP file there. Thus we will be able to gather more details about your scenario and provide you with more to-the-point answer.

Best wishes,
Radoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
robin
Top achievements
Rank 1
Answers by
robin
Top achievements
Rank 1
Radoslav
Telerik team
Share this question
or