Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Access DataList Fields?Access DataList Fields?
Previous
 
Next
New Post
4/1/2008 9:41 PM
 

Well, from the looks of it... it is just about that easy.

Including the code:  CommandName = "Update"  or CommandName = "ModuleName_Update"  just isn't enough.

In you asp:DataList put OnItemCommand=”Record_Command”

In your asp:Button (which should be in side <edititemtemplate></edititemtemplate>) put CommandName=”Update”

Then in you view.ascx.vb page put a Sub

 Sub Record_Command(ByVal src As Object, ByVal Args As DataListCommandEventArgs)

    Dim _ModuleNameInfo_data As New TemplateInfo

    Dim _tb1 As TextBox = Args.Item.FindControl("TextBox1")

    'etc. for all controls

    _ModuleNameInfo_data.FieldName = _tb1.Text.ToString()

    'etc. for all controls

    If Args.CommandName = "Update" Then

        TemplateController.Template_Update(_ModuleNameInfo_data)

    End If

End Sub

-- Nathan Rover

 
New Post
4/2/2008 12:22 PM
 



Great Tutorial!  I figured I was close already.
Your suggested code makes sense and works with elements I already have in place.  I included all fields with data being collected, to ensure update processes correctly.  Although, when I perform the update I've been getting the good old: Object reference not set to an instance of an object.

The only field that is not declared is the ID.  I went ahead and re-declared all the ModuleID, PortalID, UserID fields for update as well.
Does the update automatically associate "Update" with that selected ID, or must I declare?
Is there anything else I may be overlooking?

 
New Post
4/2/2008 1:33 PM
 

Glad you’re making progress.

I’d like to point out, and forgive me if you already know this but, unless you have a very compelling reason I would stick with a GridView over a DataList. DataList is ASP.NET 1.1 era technology and GridView is ASP.NET 2.0 era. With ASP.NET 2.0 Microsoft made a big push to “Get more done with less code” and GridView is a, IMHO, fine example of that. Amongst many other handy features (paging, sorting) GridView will keep track of the IDs for you and handle all communication between it and it’s friend (sqlDataSource). With a DataList you have to do all the coding to store every value, and handle the edit/delete functionality.

(…steps off soap box…)

Back to your problem at hand, you’ll need to have a control in your edit item template for every field you need to keep track of. Edit items don't necessarily have to be textboxes. For your ID you don’t typically want anyone to edit it, so I would use a label to hold the ID or a “disabled” textbox.

Then in your code before you call “templateController.Template_Update” every field that is needed for the update (i.e. every field in the Update function of your Controller class) must be in the collection. And because DataList doesn’t do any of the work for you… it’s up to you to make sure that each value is sent. i.e.

_ModuleNameInfo_data.FieldName = _tb1.Text.ToString()

'etc. for all controls

After that if your still getting an “Object reference not set to an instance of an object” error double and triple check your “Args.Item.FindControl(“FieldName”)” lines. Those will throw Object reference errors like crazy if you give them the wrong name. You can also do a little of this:

If Not Args.Item.FindControl("FieldName") Is Nothing Then

    Dim _tb1 As TextBox = Args.Item.FindControl("FieldName")

End If

To check and see if the control exists before you try and pull data from it.

-- Nathan Rover

 

edited for spelling.

 
New Post
4/2/2008 2:51 PM
 



Great Information.  Your acute attention & help is appreciated.
Interesting thing is I am already using complex GridViews.  The attraction to a DataList is the ability to make dynamic layouts. (not just single line data)
Although now you've got me thinking that it may be possible to achieve the same dynamic layouts within GridView Template.

I have followed this format of coding, and with all fields temporarily visible, I have verified that all values are binding correctly to textboxes.
Wouldn't a checkbox process look like this:
Dim _cb1 As CheckBox = Args.Item.FindControl("CheckBoxBox1")
ModuleNameInfo_data.FieldName = _cb1.Checked.ToString()

The Record_Command should be processing, but despite all textboxes binding correctly:  Object reference not set to an instance of an object.
I tried testing with "On Update Command= Record_Command" and/or tested a Handler with event to see if either made the difference.
Previously I only had <ItemTemplate></ItemTemplate>, but also implimented <EditItemTemplate></EditTemplate>.  So close!

With all the suggested code implimented, what else could be causing this update error?

 
New Post
4/2/2008 4:38 PM
 

Close, if your check box field in your controller is a boolean and your database datatype is a bit (like in my projects) then change

ModuleNameInfo_data.FieldName = _cb1.Checked.ToString()

to

ModuleNameInfo_data.FieldName = _cb1.Checked

That way it will pass a false or true VALUE not just a STRING that says "false" or "true"

-- Nathan Rover

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Access DataList Fields?Access DataList Fields?


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out