Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Custom Control from GridView - OldValues/NewValues not showing

Reply
Thread Tools

Custom Control from GridView - OldValues/NewValues not showing

 
 
Ryan
Guest
Posts: n/a
 
      06-18-2007
I am trying to create a custom control that would allow an
administrator to update user email addresses and to lock/unlock
accounts. The problem is that oldvalues and newvalues event arguments
of the onupdate command are blank when the control is used, making it
difficult to determine whether a value change has occured that
requires and update. I have an idea as to a way to do a workaround
using the view state, but I am curious as to what might be going
wrong. I also thought that people might find the code to-date helpful
in some of their projects:

If anyone knows why the oldvalues and newvalues aren't getting passed,
please let me know! Here is the code:

<ToolboxData("<{0}:EditUserControl runat=server></
{0}:EditUserControl>")> _
Public Class EditUserControl
Inherits GridView

Private mbrshpConnectionString As String
Private mbrshpDataSource As New SqlDataSource
Private bfUserID As New BoundField
Private bfUserName As New BoundField
Private bfEmail As New BoundField
Private chkbxfIsLockedOut As New CheckBoxField
Private cfCommand As New CommandField

<Browsable(False)> _
Shadows ReadOnly Property DataMember() As String
Get
Stop
EnsureChildControls()
Return mbrshpDataSource.ID
End Get
End Property

<Browsable(False)> _
Shadows ReadOnly Property DataSourceID() As String
Get
EnsureChildControls()
Return mbrshpDataSource.ID
End Get
End Property

Protected Overrides Sub CreateChildControls()

If Not Page.IsPostBack Then
AutoGenerateColumns = False
mbrshpDataSource.ID = "mbrshpDataSource"
If MyBase.Columns.Count = 0 Then
cfCommand.ButtonType = ButtonType.Button
cfCommand.EditText = "Edit"
cfCommand.UpdateText = "Update"
cfCommand.CancelText = "Cancel"
cfCommand.ShowCancelButton = True
cfCommand.ShowEditButton = True
cfCommand.CausesValidation = False

MyBase.Columns.Add(cfCommand)

bfUserID.HeaderText = "User ID"
bfUserID.Visible = False
bfUserID.DataField = "UserID"
MyBase.Columns.Add(bfUserID)

bfUserName.HeaderText = "Login ID"
bfUserName.DataField = "UserName"
bfUserName.ReadOnly = True
MyBase.Columns.Add(bfUserName)

bfEmail.HeaderText = "Email"
bfEmail.DataField = "Email"
MyBase.Columns.Add(bfEmail)

chkbxfIsLockedOut.HeaderText = "Account Locked"
chkbxfIsLockedOut.DataField = "IsLockedOut"
MyBase.Columns.Add(chkbxfIsLockedOut)

End If

End If
End Sub
Protected Sub OnEdit(ByVal sender As Object, ByVal e As
GridViewEditEventArgs) Handles MyBase.RowEditing
sender.EditIndex = e.NewEditIndex
sender.databind()
End Sub

Protected Sub OnUpdate(ByVal sender As Object, ByVal e As
GridViewUpdateEventArgs) Handles MyBase.RowUpdating
Dim i As Integer
If Not DesignMode Then
Page.Response.Write("Here they are:")
For i = 0 To e.OldValues.Count - 1
Page.Response.Write(e.OldValues(i).ToString)
Next
For i = 0 To e.NewValues.Count - 1
Page.Response.Write(e.NewValues(i).ToString)
Next

End If
sender.databind()
End Sub

Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
Dim curPage As System.Web.UI.Page
curPage = Page

If mbrshpConnectionString = "" Then
If Not Me.DesignMode Then
mbrshpConnectionString =
CustomWebControls.ConfigurationAccessMethods.GetDe faultMemberStoreConnectionString(curPage.Request.A pplicationPath)
End If
End If

mbrshpDataSource.ID = "mbrshpDataSource"
mbrshpDataSource.ConnectionString = mbrshpConnectionString
mbrshpDataSource.SelectCommandType =
SqlDataSourceCommandType.StoredProcedure
mbrshpDataSource.SelectCommand =
"dbo.aspnet_Membership_GetAllUsers"
mbrshpDataSource.SelectParameters.Add("Application Name",
Membership.ApplicationName)
mbrshpDataSource.SelectParameters.Add("PageIndex",
Me.PageIndex)
mbrshpDataSource.SelectParameters.Add("PageSize",
Me.PageSize)
MyBase.DataSource = mbrshpDataSource
Dim datakeys(0) As String
datakeys(0) = "UserID"
MyBase.DataKeyNames = datakeys
MyBase.EnsureDataBound()
If Not curPage.IsPostBack Then
MyBase.DataBind()
End If
End Sub
End Class

 
Reply With Quote
 
 
 
 
Ryan
Guest
Posts: n/a
 
      06-20-2007
My thought for a work around was to add the old items from my control
at the edit event and persist them in the control state. This works
for the old items. But the new values are also not being passed and I
do not know how to get the values from the control once the update
event has fired. The control comes over with no rows... Does anyone
have any ideas as to how I might get the entered values from the
gridview?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
gridview control not showing selected row sytle sheet Rafia Tapia ASP .Net 3 03-24-2008 01:44 AM
Custom Web Control not showing up in Toolbox John Kotuby ASP .Net 5 05-11-2007 12:22 PM
ASP 1.1: DataGrid - Showing/Not Showing Buttons Ray Booysen ASP .Net 2 03-28-2006 02:49 PM
asp.net custom server control not showing when dragged onto web fo SpencerW ASP .Net Web Controls 5 05-27-2005 12:58 AM
ControlDesigner not invoked on custom control when control is rendered within another custom control Matt Sokol ASP .Net Building Controls 2 08-07-2003 07:13 AM



Advertisments