Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 29th, 2012, 04:41 AM
Authorized User
Points: 109, Level: 2
Points: 109, Level: 2 Points: 109, Level: 2 Points: 109, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2012
Posts: 29
Thanks: 11
Thanked 0 Times in 0 Posts
Default ItemInserting or ItemInserted?

what will i do to make the dropdownlist values change after i insert a new data in a details view? ItemInserting or ItemInserted?


Code:
Imports AlumniTblModel
Partial Class Management_Sample
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Using myEntities As New AlumniTblEntities

            Dim allProvinces = From province In myEntities.ProvinceTbls
                               Order By province.Province
                               Select province.Province




            ProvinceGrid.DataSource = allProvinces
            ProvinceGrid.DataBind()
            ProvinceGrid.HeaderRow.Cells(0).Text = "Provinces"

        End Using
    End Sub

    Protected Sub DetailsView1_ItemInserted(sender As Object, e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs) Handles DetailsView1.ItemInserted

        Using myEntities As New AlumniTblEntities

            Dim allProvinces = From province In myEntities.ProvinceTbls
                               Order By province.Province
                               Select province.Province



            If Not IsPostBack Then
                With ProvinceDdl
                    .DataValueField = "Province"
                    .DataTextField = "Province"
                    .DataSource = allProvinces
                End With
                DataBind()

            End If

        End Using

    End Sub

End Class
I used both ItemInserting and ItemInserted but the DropDownList Control values does not update unless you close the browser and re-run the application again.
Reply With Quote
  #2 (permalink)  
Old August 29th, 2012, 05:28 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

I have no idea what you're asking. Sorry.

Also, since this is not directly related to my book, please post questions like these in a general ASP.NET catergory from this list: http://p2p.wrox.com/asp-net-4-539/

heers,

Imnar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #3 (permalink)  
Old August 30th, 2012, 02:58 AM
Authorized User
Points: 109, Level: 2
Points: 109, Level: 2 Points: 109, Level: 2 Points: 109, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2012
Posts: 29
Thanks: 11
Thanked 0 Times in 0 Posts
Default

yes it is related on your book sir. Im using the things i learned from chapter 13 page 459 under the title Using DetailsView to Insert and Update Data.
Reply With Quote
  #4 (permalink)  
Old August 30th, 2012, 03:17 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

But I still don't understand the question.... ;-)

Maybe it's the check for IsPostBack? That returns true in the ItemInserted event.

Also, consider moving code like this to a sub or function. The stuff in Load and ItemIsnerted is almost the same, forcing you to code and maintain similar code in multiple locations.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!

Last edited by Imar; August 30th, 2012 at 03:40 AM..
Reply With Quote
  #5 (permalink)  
Old August 30th, 2012, 03:37 AM
Authorized User
Points: 109, Level: 2
Points: 109, Level: 2 Points: 109, Level: 2 Points: 109, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2012
Posts: 29
Thanks: 11
Thanked 0 Times in 0 Posts
Default

what i mean is this. if i entered a data in the detailsview, the dropdownlist control which display the data inserted using the detailsview should be updated after i insert the data. but it seems not it. i have to close the browser, and re run the application again to see if the data is added in the drop down list
Reply With Quote
  #6 (permalink)  
Old August 30th, 2012, 03:40 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hence my remark: Maybe it's the check for IsPostBack? That returns true in the ItemInserted event. You're not rebinding the drop down list in ItemInserted.

Debug your page and break into ItemInserted to see what I mean....

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #7 (permalink)  
Old August 30th, 2012, 04:03 AM
Authorized User
Points: 109, Level: 2
Points: 109, Level: 2 Points: 109, Level: 2 Points: 109, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2012
Posts: 29
Thanks: 11
Thanked 0 Times in 0 Posts
Default

can you suggest some things how to do rebinding in the dropdownlist after a data has been inserted? i don't know about the load function. and is there a refresh function for dropdownlist?
Reply With Quote
  #8 (permalink)  
Old August 30th, 2012, 04:05 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

You're doing the right thing; you just need to remove the check for IsPostback. With Load, I was referring to Page_Load.

FWIIW: all of this is taken care off if you use the data-source controls. I still haven't seen a compelling reason to do all of this in code. More work, more maintenance, while, IMO, it doesn't add much value here.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
rmanapul (August 30th, 2012)
  #9 (permalink)  
Old August 30th, 2012, 04:15 AM
Authorized User
Points: 109, Level: 2
Points: 109, Level: 2 Points: 109, Level: 2 Points: 109, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2012
Posts: 29
Thanks: 11
Thanked 0 Times in 0 Posts
Default

yeah im doing this all in hard coding LINQ to Entities for me to learn more of it in coding practice.
Reply With Quote
  #10 (permalink)  
Old August 30th, 2012, 04:42 AM
Authorized User
Points: 109, Level: 2
Points: 109, Level: 2 Points: 109, Level: 2 Points: 109, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2012
Posts: 29
Thanks: 11
Thanked 0 Times in 0 Posts
Default

thanks i found a solution by using this code:

Code:
Imports AlumniTblModel
Partial Class Management_Sample
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Using myEntities As New AlumniTblEntities

            Dim allProvinces = From province In myEntities.ProvinceTbls
                               Order By province.Province
                               Select New With {province.Province}




            ProvinceGrid.DataSource = allProvinces
            ProvinceGrid.DataBind()
            ProvinceGrid.HeaderRow.Cells(0).Text = "Provinces"

            ProvinceDdl.DataSource = allProvinces
            ProvinceDdl.DataValueField = "Province"
            ProvinceDdl.DataTextField = "Province"
            ProvinceDdl.DataBind()



        End Using
    End Sub

    Protected Sub DetailsView1_ItemInserted(sender As Object, e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs) Handles DetailsView1.ItemInserted
        Using myEntities As New AlumniTblEntities

            Dim allProvinces = From province In myEntities.ProvinceTbls
                               Order By province.Province
                               Select New With {province.Province}




            ProvinceGrid.DataSource = allProvinces
            ProvinceGrid.DataBind()
            ProvinceGrid.HeaderRow.Cells(0).Text = "Provinces"

            ProvinceDdl.DataSource = allProvinces
            ProvinceDdl.DataValueField = "Province"
            ProvinceDdl.DataTextField = "Province"
            ProvinceDdl.DataBind()



        End Using
    End Sub
End Class
it works perfectly now :)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 12: ItemInserted; Endediting not declared ChristopherS BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 0 September 28th, 2011 11:44 PM



All times are GMT -4. The time now is 03:01 AM.


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