 |
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 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
|
|
|
|
|

August 29th, 2012, 04:41 AM
|
|
Authorized User
|
|
Join Date: May 2012
Posts: 29
Thanks: 11
Thanked 0 Times in 0 Posts
|
|
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.
|
|

August 29th, 2012, 05:28 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

August 30th, 2012, 02:58 AM
|
|
Authorized User
|
|
Join Date: May 2012
Posts: 29
Thanks: 11
Thanked 0 Times in 0 Posts
|
|
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.
|
|

August 30th, 2012, 03:17 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
Last edited by Imar; August 30th, 2012 at 03:40 AM..
|
|

August 30th, 2012, 03:37 AM
|
|
Authorized User
|
|
Join Date: May 2012
Posts: 29
Thanks: 11
Thanked 0 Times in 0 Posts
|
|
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
|
|

August 30th, 2012, 03:40 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

August 30th, 2012, 04:03 AM
|
|
Authorized User
|
|
Join Date: May 2012
Posts: 29
Thanks: 11
Thanked 0 Times in 0 Posts
|
|
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?
|
|

August 30th, 2012, 04:05 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

August 30th, 2012, 04:15 AM
|
|
Authorized User
|
|
Join Date: May 2012
Posts: 29
Thanks: 11
Thanked 0 Times in 0 Posts
|
|
yeah im doing this all in hard coding LINQ to Entities for me to learn more of it in coding practice.
|
|

August 30th, 2012, 04:42 AM
|
|
Authorized User
|
|
Join Date: May 2012
Posts: 29
Thanks: 11
Thanked 0 Times in 0 Posts
|
|
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 :)
|
|
 |
|