Link to home
Start Free TrialLog in
Avatar of EugeneC
EugeneC

asked on

Populate detailsview from gridview via generic list

I am populating a gridview from a generic list as follows

      ProgrammeCollection programList = new ProgrammeCollection();        

        //the "PopulateAllUsersFromDatabase" method calls the
        //"UserDataHelper.PopulateDataList" method that returns a generic collection (UserCollection) of user objects      
        programList.PopulateAllProgrammesFromDatabase();

        //bind the grid
        UserGridView.DataSource = programList;
        UserGridView.DataBind();
     
I need to be able to use the detailsview control with the grid.  For example, if
you select a column in the datagrid then the detailsview is populated with the
record, eventually I want to be able to edit details in the view.

Regards
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

What problems are you having?  Have you tried anything yet?

Bob
Avatar of EugeneC
EugeneC

ASKER

Hi Bob

No I have not - I have not used them before.
If you are binding to a GridView, then binding to a DetailsView is very similar.  You would need to define the Fields that would bind to the properties for the bound object.

Bob
Avatar of EugeneC

ASKER

Do you have an example Bob?
Example:

        <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Style="z-index: 100;
            left: 60px; position: absolute; top: 36px" Width="125px" AutoGenerateRows="False">
            <Fields>
                <asp:BoundField DataField="Name" />
                <asp:BoundField DataField="Address" />
            </Fields>
        </asp:DetailsView>
 
public class Person
{
    private string _name = "";
    private string _address = "";

    public string Name
    {
        get { return _name; }
        set { _name = value; }
    }

    public string Address
    {
        get { return _address; }
        set { _address = value; }
    }

}

Bob
Avatar of EugeneC

ASKER

Thanks

Is there a way to do it totally in code behind c#?
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial