Wrox Programmer Forums
|
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
 
Old January 26th, 2007, 05:41 PM
Authorized User
 
Join Date: Jul 2006
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default

actually come to think of it arent the parameters readonly in the updating event?

 
Old January 26th, 2007, 05:50 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Did you look at the Default page in the Bugs folder I mentioned?

It has an example that shows you how to do this....

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.
 
Old January 26th, 2007, 05:59 PM
Authorized User
 
Join Date: Jul 2006
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default

one thing i did was remove the dataobjecttypename from the objds..i think that was one thing that i had wrong

so now i create a new ticket object in the updating handler
and assign all the pertinent values to it correct?
how do i pull the values from controls nested in templates in my grid?

thanks so much
justin

 
Old January 26th, 2007, 06:26 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I may have been a little confused by what you're trying to achieve, in turn confusing you.

If you have an update method that accepts an object of your type (e.g. a Ticket), the entire object is in e.InputParameters. So, you can do something like this:

CType(e.InputParameters(0), Ticket).Status.Value = NewValue

This way, you modify the Status parameter of the Ticket object.

If you have a method that accepts individual arguments (e.g.

Public Function UpdateTicket (ByVal id As Integer, title As String, status As NameValue....)

then you *can* modify the parameters in the Updating event:

e.InputParameters("Title") = "Some Title"

Does this give you some ideas to work with?

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.
 
Old January 26th, 2007, 06:47 PM
Authorized User
 
Join Date: Jul 2006
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default

holy goodness it worked!!!

i tried your first suggestion but received an error that i could not cast from type string to type ticket...then i remembered i had removed the dataobjecttypename attribute, so i replaced it with ticket and voila! the parameter for location.value that i hard coded to '2' worked.....now can you help me to get refernce to the properties of the controls within the templates of the grid?

 
Old January 27th, 2007, 12:56 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

In that case, you may be better off handling the RowUpdating event of the GridView instead of the Updating event of the DataSource.

Here's a quick example:
Code:
Protected Sub GridView1_RowUpdating(_
      ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) _
      Handles GridView1.RowUpdating
  Dim myTextBox As TextBox = _
          CType(GridView1.Rows(e.RowIndex).FindControl("TextBox1"), TextBox)
  e.NewValues("LastName") = myTextBox.Text
End Sub
This code use e.RowIndex to retrieve the row being edited. It then searches for the text box called TextBox1, and assigns its Text to e.NewParameters, in this case a LastName field.

For this to work, your GridView needs a template that contains the TextBox, like this:
Code:
<asp:TemplateField HeaderText="LastName" SortExpression="LastName">
  <EditItemTemplate>
    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("LastName") %>'></asp:TextBox>
  </EditItemTemplate>
  <ItemTemplate>
    <asp:Label ID="Label2" runat="server" Text='<%# Bind("LastName") %>'></asp:Label>
  </ItemTemplate>
</asp:TemplateField>
Hope this helps,

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.
 
Old January 27th, 2007, 01:38 PM
Authorized User
 
Join Date: Jul 2006
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok back to the problem of binding. Its easy to bind the textbox to a simple property like "lastname". the problem is binding to properties like a namevalue.value . am i going to just have to give up on using namevalue properties?
that is why we decided to set the properties of the ticket object in the updating event, because of the problems with binding to a complex object...whether it be the grid or objectdatasource updating event...now we are back to the problem of binding to a complex object.

 
Old January 27th, 2007, 02:02 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

It all depends. Using complex objects like the NameValue requires a little more code than with simple objects. However, the principle stays the same.

Here's a sample GridView template. It uses a Bug class with a Status property that is of type NameValue:
Code:
<asp:TemplateField HeaderText="Status" SortExpression="Status">
  <EditItemTemplate>
    <asp:DropDownList ID="DropDownList1" runat="server" 
          SelectedValue='<%# CType(Eval("Status"), NameValue).Value %>'>
      <asp:ListItem Value="33">Item 33</asp:ListItem>
      <asp:ListItem Value="1">Item 1</asp:ListItem>
    </asp:DropDownList>
  </EditItemTemplate>
  <ItemTemplate>
    <asp:Label ID="Label1" runat="server" 
        Text='<%# CType(Eval("Status"), NameValue).Name %>'></asp:Label>
  </ItemTemplate>
</asp:TemplateField>
As you can see, I am using Eval instead of Bind to display the Name in the ItemTemplate and I use CType(Eval("Status"), NameValue).Value to preselect an item in the dropdown.

Next, I have the following code in the Updating event of the DropDown, almost identical to the code I posted earlier, except for the fact I am creating a new NameValue instance with a fake name:
Code:
Dim myList As DropDownList = _
        CType(GridView1.Rows(e.RowIndex).FindControl("DropDownList1"), DropDownList)
e.NewValues("Status") = New NameValue("Fake Name", myList.SelectedValue)
When finally the UpdateItem method is called, it accepts an instance of Bug with its Status set to the NameValue created in the code above.

As you can see, it requires more work than simple properties. However, once you understand how it works, it's much easier to apply it, and keep using complex objects like NameValue.

Hopefully, this post helps you understand how to do databinding with complex objects...

Cheers,

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
While typing this post, I was listening to: Future Proof by Massive Attack (Track 1 from the album: 100th Window) What's This?
 
Old January 27th, 2007, 02:33 PM
Authorized User
 
Join Date: Jul 2006
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default

great...thanks

how and when do I assign the values e.newvalues to my ticket object?

 
Old January 27th, 2007, 02:52 PM
Authorized User
 
Join Date: Jul 2006
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default

you say updating event of the dropdown...is that a typo?






Similar Threads
Thread Thread Starter Forum Replies Last Post
Binding Controls zulf Infopath 0 October 8th, 2007 11:22 PM
Need help binding RadioButtonList binici ASP.NET 2.0 Basics 5 May 11th, 2007 06:12 PM
data binding g2000 ASP.NET 2.0 Basics 0 January 13th, 2006 03:36 PM
binding of textbox sdibartolomeo ADO.NET 0 November 10th, 2003 02:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.