View Single Post
  #1 (permalink)  
Old November 13th, 2007, 01:46 PM
Itech Itech is offline
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.