p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Professional (http://p2p.wrox.com/forumdisplay.php?f=215)
-   -   Cannot Update the vals in a Dynamic DetailsView (http://p2p.wrox.com/showthread.php?t=63729)

Itech November 13th, 2007 01:46 PM

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.


dparsons November 13th, 2007 01:50 PM

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

Itech November 13th, 2007 02:12 PM

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?


dparsons November 13th, 2007 02:15 PM

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

Itech November 13th, 2007 02:21 PM

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?


Itech November 13th, 2007 04:22 PM

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.


Kuong April 2nd, 2008 01:59 AM

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.




All times are GMT -4. The time now is 11:38 PM.

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