 |
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6
 | This is the forum to discuss the Wrox book ASP.NET 2.0 Instant Results by Imar Spaanjaars, Paul Wilton, Shawn Livermore; ISBN: 9780471749516 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|
|

January 26th, 2007, 10:47 AM
|
|
Authorized User
|
|
Join Date: Jul 2006
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
NameValue and Binding
Imar,
Please help!? Im not sure if this has come up before but I am really stumped when it comes to 2 way binding when you have an object that has a nested object...like in my problem I have a ticket object, and the ticket object has public properties like id, description, etc which are all integers and strings and easy to bind to in the aspx page code with some code like <%# bind("id") %>. The ticket also has some NameValue properties like location (which is a building), category (like hardware, software, etc) which are good for holding the id and description for items in lookup tables. The itemtemplate part is easy because you can use the eval() function and it will recognize a namevalue object like say I wanted to show the location description on the gridview i just put in <%# eval("location.name")%> ......But i cant bind to these objects easily, or I cant figure out how. One way I was going to try was to have a simple helper function in the code behind that would accept the namevalue object and just return the id (integer) portion. But I cant figure out the syntax to do this in the aspx markup. First I tried things like <%# bind(helper("location")) %> which failed, something is wrong with the syntax. And then I tried stuff like <%# helper(eval("location")) %> which does work as far as getting the value, but it doesnt bind and therefore doesnt pass the value on an update. As I watch in debug on update from edit mode in a gridview, I can see that the namevalue properties of my ticket object that are passed to my ticketmanagerdb function are set to their default values (an empty string, and -1).
One workaround for this that I am really trying to avoid is to just have the id properties of the namevalue objects represented as public properties as well...like for instance locationid or categoryid. But then of course what is the purpose of having the namevalue then if i also have to carry the id separately.
Imar can you please help I was up till 3:00 am last night with this binding problem.
Thanks
Justin
|
|

January 26th, 2007, 10:48 AM
|
|
Authorized User
|
|
Join Date: Jul 2006
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I might also add if its not apparent that what I am trying to bind is the selectedvalue of comboboxes when in edit mode on a gridview.
|
|

January 26th, 2007, 12:21 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi Justin,
.NET 2 isn't very good at binding complex objects. Maybe next versions of the framework will support it, but until then we have to live with the limitations.
One way to solve your problem is to drop two-way binding, and resort to single binding (Eval) instead. Here's an example:
<asp:TextBox ID="TextBox1" runat="server" Text='<%# CType(Eval("Status"), NameValue).Name %>'></asp:TextBox>
This casts the data object to a NameValue object and then retrieves its name.
Does this help?
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
|
|

January 26th, 2007, 12:46 PM
|
|
Authorized User
|
|
Join Date: Jul 2006
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Imar,
thanks for the quick reply. Well i see what youre doing there...but that doesnt Exactly solve my problem because when I use eval, it works to display the correct value like in a combobox.
NOTE: here is the helper function
public function helper (byval nvobject as namevalue) as integer
return nvobject.value
end function
You see like I posted earlier if I use the <%# helper(eval("location")) %> or
<%# eval(helper("location")) %> (i cant remeber which one it was so late) for say instance the selectedvalue property of a combobox (which uses a SQLdatasource to be populated with all the item ids and descriptions) then when in edit mode the dropdownlist will 'bind' correctly in the sense that it will take the id (integer) that is returned from the helper function and display the correct location description in the combobox. The problem herein lies when I click the update button. The value in the combobox...whether I change it or leave it the same is not being passed somewhere along the line...and I assume it starts in the gridview...and goes on through my objectdatasource till it gets to the ticketmanagerdb class and the insertupdateticket function. There I can see that none of the namevalue.value properties are being retained or passed. So I guess the bind did not work correctly. Please excuse my lack of knowledge of the true inner workings of binding and how these values are passed around between the gridview and objectdatasource.
|
|

January 26th, 2007, 01:26 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
You're using Eval, which doesn't support two-way data binding. Instead, you normally use Bind which *does* support two-way data binding (that is, display it, and be able to retrieve it again afterwards). However, Bind doesn't work with complex objects.
To solve this problem, you can take the approach I used in the BugBase application in the AddEditBug.aspx page: create your own object, assign values and save it.
As an alternative, look at Default.aspx in the Bugs folder. The code has a handler for ObjectDataSource1_Selecting that gets the value from a drop down and assigns it to the e.InputParameters collection. You'll need to use a different event (Inserting or Updating) but the concepts are roughly the same.
HtH,
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
|
|

January 26th, 2007, 02:26 PM
|
|
Authorized User
|
|
Join Date: Jul 2006
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
so youre saying i can either
1) create my ticket object, then call the ticketmanager(pass the ticket) method explicitly without an objdatasource....so this way i cannot use a gridview, correct? which is ok i guess, i can just populate the textboxes, dropdowns, etc and then pull their values into a ticket object and call my ticketmanager function..correct?
this works good except i cant use the gridview (which i am using teleriks radgrid, so that would be nice!)
2)this maybe sounds like it might work better for me so i can use my radgrid. i think i had played around with this before...do i just have to add my dropdownlist.selectedvalues to my ticket.namevalue.value and then ....no no, thats not it...the objectdatasource e.inputparameters...these represent my object (a ticket) or no? how do i name the parameters I am adding?
e.inputparameters.add(
|
|

January 26th, 2007, 02:29 PM
|
|
Authorized User
|
|
Join Date: Jul 2006
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
And am i adding the parameters from the controls from inside the grid? How do i get a refernce to those controls that are nested inside templates of the gridview while in the objectdatasource_updating event
|
|

January 26th, 2007, 03:02 PM
|
|
Authorized User
|
|
Join Date: Jul 2006
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
am i adding the parameters according to properties of my storedprocedure...or according to my properties of my ticket object
|
|

January 26th, 2007, 05:33 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Quote:
|
quote:am i adding the parameters according to properties of my storedprocedure...or according to my properties of my ticket object
|
The latter. Your ObjectDataSource has a number of arguments for the update method. The InputParameters keeps a collection of the arguments with the same name.
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
|
|

January 26th, 2007, 05:37 PM
|
|
Authorized User
|
|
Join Date: Jul 2006
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
can you give me a little more info on what to do in the updating event. i can see my ticket if i put in e.inputparameters.item(0) but how do i manipulate the ticket and assign the values?
|
|
 |