Solved

Populate detailsview from gridview via generic list

Posted on 2006-11-13
7
900 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:EugeneC
  • 4
  • 3
7 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17929228
What problems are you having?  Have you tried anything yet?

Bob
0
 

Author Comment

by:EugeneC
ID: 17929254
Hi Bob

No I have not - I have not used them before.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17929274
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
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

Author Comment

by:EugeneC
ID: 17929304
Do you have an example Bob?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17929453
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
0
 

Author Comment

by:EugeneC
ID: 17937041
Thanks

Is there a way to do it totally in code behind c#?
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 17937398
Try this:

BoundField field = new BoundField();
field.DataField = "Name";
this.DetailsView.Fields.Add(field);

field = new BoundField();
field.DataField = "Address";
this.DetailsView.Fields.Add(field);

Bob
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question