Solved

Populate detailsview from gridview via generic list

Posted on 2006-11-13
7
907 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

839 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