Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Populate detailsview from gridview via generic list

Posted on 2006-11-13
7
Medium Priority
?
939 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 2000 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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Loops Section Overview
Suggested Courses
Course of the Month21 days, 4 hours left to enroll

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