 |
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 Professional 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
|
|
|

November 13th, 2007, 01:46 PM
|
Registered User
|
|
Join Date: Nov 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Cannot Update the vals in a Dynamic DetailsView
Hello All,
Here is my scenario. I have two Webcontrols a GridView and a DetailsView.
Due to the nature of the database (Soft database design) i have created a custom bound field so i can dynamically create a bound field and specify whether the field is a textbox/label/checkbox/dropdownlist/etc.
Anyhow, when i dynamically create the columns and add them to the Gridview and Details View, it displays correctly.
Here's where it gets funny.
Upon clicking the update button, i can successfully extract the webcontrols from the Gridview by accessing them through this method:
private bool ParseGView(GridView view)
{
if (view.Rows.Count <= 0)
return false;
// loop, parse, save info
foreach (GridViewRow r in view.Rows)
{
foreach (TableCell cell in r.Cells)
{
if (cell.Controls.Count <= 0)
continue;
SaveElement((WebControl)cell.Controls[0]); // this determines the type (Textbox/DDL/etc) and extracts the value approriately
}
}
return true;
}
This viewstate maintains correctly and all is good.
BUT, when trying to extract the values from the DetailsView, it simply doesn't maintain the viewstate and all i get is a blank Label with Text=''. Here is the method of retrival, same as the Gridview pretty much.
private bool ParseDView(DetailsView view)
{
if (view.Rows.Count <= 0)
return false;
// loop, parse, save info
foreach (DetailsViewRow r in view.Rows)
{
if (r.Cells.Count <= 1)
continue;
SaveElement((WebControl)r.Cells[1].Controls[0]); // this is the cell with the webcontrol
}
return true;
}
Any thoughts on why the DetailsView will not hold the values?
ANd i am programatically databinding as an FYI.
|

November 13th, 2007, 01:50 PM
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
Do you rebind your DetailsView before the ParseDView function is called? If not, try doing that first.
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========
|

November 13th, 2007, 02:12 PM
|
Registered User
|
|
Join Date: Nov 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thank you very much for the prompt reply.
ok, in my click event, i set a breakpoint before the databind, it shows that i have 7 rows, after the databind, it removed the rows and ended up with 0.
I did not re set the datasource as i figure that would erase the values i updated within my textboxes within the form.
any additional thoughts?
|

November 13th, 2007, 02:15 PM
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
If you don't change datasources how do you have 7 rows on click but then 0 rows after the databind. That doesn't seem right.
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========
|

November 13th, 2007, 02:21 PM
|
Registered User
|
|
Join Date: Nov 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
exactly it doesn't.
keep in mind, on page load i am setting the Datasource programatically to a datatable ( if (!IsPostBack) ). I am NOT using an object datasource or SQL Datasource. So onclick, i'm assuming it holds the viewstate that is why it shows 7 rows. what are your thoughts on the next steps?
|

November 13th, 2007, 04:22 PM
|
Registered User
|
|
Join Date: Nov 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
update.
instead of programatically setting the datasource to a datatable i used an objectdatasource to see if i had any better luck.
well, i too your suggestion and in the onclick, i DetailsView1.Databind() in the click event and it just simply gave me back the default values that were retrieved from the database.
anyways, this functionality works fine with a gridview, but not with a detailsview. do you have anything else i can try out?
thanks for your help.
|

April 2nd, 2008, 01:59 AM
|
Registered User
|
|
Join Date: Apr 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I have the same problem, by when i try get direct values in the event method, it's seem ok.
for (int i = 1; i < detailsView.Rows.Count ; i++)
{
string labelValue = detailsView.Rows[i].Cells[0].Text;
string contentValue = ((TextBox)detailsView.Rows[i].Cells[1].Controls[0]).Text;
}
when get from other method it problem again.
And i have other problem, anybody can help me please. How can i customize textbox in detailsview edit mode.
|
|
 |