How can I use an ASP Linkbutton to pull information from a database? When the user clicks on the link I want all information for that record to be displayed

Posted on 2011-10-14
Last Modified: 2012-06-27
Hello. I have a page where I am using a listview to display information from my database. For each record I am only displaying a few fields. I have the name fields listed as linkbuttons b'c I want the user to be able to click on the name and be able to see more information which will basically pull all the fields for that record. Can anyone tell me how to do this?
Question by:cdlciddit
    LVL 19

    Accepted Solution

    You can do this by following way
    First you need to change your name field from asp:Label to asp:Link like following

    Your Code -
    <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("YourName") %>' /> 

    Open in new window

    Change Code-

    <asp:LinkButton ID="lnkbtn" runat="server" Text='<%# Eval("YourName") %>' ><%# Eval("YourName") %></asp:LinkButton>

    Open in new window

    To fetch record from database when user click on Name Link Button, add ItemCommand Event to ListView like following  

     protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
                if (e.CommandName == "Select")
                    LinkButton btn = e.CommandSource as LinkButton;
                    string find = btn.Text;

    Open in new window

    From Above code you will get the selected Name in the find string
    From Name find related records from database by adding your code below the given (above) code


    Author Comment

    Thanks. This is exactly what I needed. Sorry it took me so long to respond. I had to convert it to VB and that took some time b'c I'm not a programmer. But that worked. Thanks a lot.

    Author Closing Comment

    This is exactly what I needed to fix my problem.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
    Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    737 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

    18 Experts available now in Live!

    Get 1:1 Help Now