• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 360
  • Last Modified:

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

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?
0
cdlciddit
Asked:
cdlciddit
  • 2
1 Solution
 
Manoj PatilSr. Software EngineerCommented:
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


0
 
cdlcidditAuthor Commented:
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.
0
 
cdlcidditAuthor Commented:
This is exactly what I needed to fix my problem.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Network Scalability - Handle Complex Environments

Monitor your entire network from a single platform. Free 30 Day Trial Now!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now