Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 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
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 13th, 2007, 01:46 PM
Registered User
 
Join Date: Nov 2007
Location: Chicago, IL, USA.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.

  #2 (permalink)  
Old November 13th, 2007, 01:50 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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
================================================== =========
  #3 (permalink)  
Old November 13th, 2007, 02:12 PM
Registered User
 
Join Date: Nov 2007
Location: Chicago, IL, USA.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?

  #4 (permalink)  
Old November 13th, 2007, 02:15 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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
================================================== =========
  #5 (permalink)  
Old November 13th, 2007, 02:21 PM
Registered User
 
Join Date: Nov 2007
Location: Chicago, IL, USA.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?

  #6 (permalink)  
Old November 13th, 2007, 04:22 PM
Registered User
 
Join Date: Nov 2007
Location: Chicago, IL, USA.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

  #7 (permalink)  
Old April 2nd, 2008, 01:59 AM
Registered User
 
Join Date: Apr 2008
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.


 


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
Saving Original Data via DetailsView Update kevorkian ASP.NET 2.0 Basics 5 May 29th, 2008 01:47 PM
DetailsView update not working. Andrew.Berry ASP.NET 2.0 Professional 6 April 22nd, 2008 11:23 AM
DetailsView update onclick on LinkButton yukijocelyn ASP.NET 2.0 Basics 1 September 10th, 2007 03:43 AM
Replace xml attribs vals with xslt andye XSLT 2 July 30th, 2006 06:48 PM
Retrieve control vals modified with javascript? dungerdanish General .NET 4 June 25th, 2005 04:42 PM



All times are GMT -4. The time now is 08:10 PM.


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