Solved

Populate detailsview from gridview via generic list

Posted on 2006-11-13
7
878 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now