| Public Shared connectionString As String = ("Server=XXXXX") |
| |
| |
| Public Shared Function GetDataTableRadGrid(ByVal Sql As String) As DataTable |
| |
| Dim conn As New SqlConnection(connectionString) |
| Dim adapter1 As New SqlDataAdapter |
| adapter1.SelectCommand = New SqlCommand(Sql, conn) |
| |
| Dim Grid As New DataTable |
| conn.Open() |
| |
| Try |
| adapter1.Fill(Grid) |
| Finally |
| conn.Close() |
| End Try |
| |
| Return Grid |
| |
| End Function |
| |
| Public ReadOnly Property ProfileTable() As DataTable |
| |
| Get |
| Dim obj As Object = Me.Session("Profile") |
| If (Not obj Is Nothing) Then |
| Return CType(obj, DataTable) |
| End If |
| |
| Dim myDataTable As DataTable = New DataTable |
| myDataTable = GetDataTableRadGrid("SELECT * FROM Profile Where Status='A' Order By KProfile") |
| Me.Session("Profile") = myDataTable |
| Return myDataTable |
| End Get |
| |
| End Property |
| |
| Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load |
| |
| Session.Clear() |
| |
| End Sub |
| |
| Public Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.WebControls.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource |
| |
| MeMe.RadGrid1.DataSource = Me.ProfileTable |
| |
| End Sub |
| |
| Public Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid1.PreRender |
| |
| If Not IsPostBack Then |
| Me.RadGrid1.MasterTableView.Items(1).Edit = False |
| Me.RadGrid1.MasterTableView.Rebind() |
| End If |
| |
| End Sub |
| |
| Public Sub RadGrid1_UpdateCommand(ByVal source As Object, ByVal e As Telerik.WebControls.GridCommandEventArgs) Handles RadGrid1.UpdateCommand |
| |
| Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem) |
| Dim MyUserControl As UserControl = CType(e.Item.FindControl(GridEditFormItem.EditFormUserControlID), UserControl) |
| |
| 'Locate the changed row in the DataSource |
| Dim changedRows As DataRow() = Me.ProfileTable.Select("ProfileIDProfileID = " & editedItem.OwnerTableView.DataKeyValues(editedItem.ItemIndex)("ProfileID")) |
| |
| |
| If (Not changedRows.Length = 1) Then |
| e.Canceled = True |
| Return |
| End If |
| |
| 'Update new values |
| Dim newValues As Hashtable = New Hashtable |
| |
| newValues("ADName") = CType(MyUserControl.FindControl("ADName"), DropDownList).SelectedItem.Text |
| newValues("ADProfile") = CType(MyUserControl.FindControl("ADProfile"), TextBox).Text |
| |
| Dim cnn As New SqlConnection(connectionString) |
| Dim strUpdate As String |
| Dim cmdUpdate As SqlCommand |
| |
| strUpdate = "Update Profile Set ADName=@ADName, ADProfile=@ADProfile Where ProfileID=@ProfileID" |
| cmdUpdate = New SqlCommand(strUpdate, cnn) |
| |
| cmdUpdate.Parameters.AddWithValue("@ADName", "ADName") |
| cmdUpdate.Parameters.AddWithValue("@ADProfile", "ADProfile") |
| cmdUpdate.Parameters.AddWithValue("@ProfileID", "ProfileID") |
| |
| |
| cnn.Open() |
| cmdUpdate.ExecuteNonQuery() |
| cnn.Close() |
| |
| changedRows(0).BeginEdit() |
| Try |
| Dim entry As DictionaryEntry |
| For Each entry In newValues |
| changedRows(0)(CType(entry.Key, String)) = entry.Value |
| Next |
| changedRows(0).EndEdit() |
| Me.ProfileTable.AcceptChanges() |
| Catch ex As Exception |
| changedRows(0).CancelEdit() |
| e.Canceled = True |
| End Try |
| |
| End Sub |
| |