Solved

Using a LinkButton in a gridView column

Posted on 2008-06-10
3
3,074 Views
Last Modified: 2008-06-11
Hello,

I am using a LinkButton in a GridView I am using. In the same column there is also a label.

<asp:TemplateField HeaderText="Computer">
<ItemTemplate>
  <label id="lblComputerName" runat="server" style="cursor:hand;">
  <%# DataBinder.Eval(Container, "DataItem.computerName")%>
</label>
<asp:Panel CssClass="popupMenu" ID="PopupMenu" runat="server">
  <div style="border:1px outset red;padding:2px;width:100px">
  <div><asp:LinkButton ID="lnkStart" Enabled="false" runat="server" OnClick="StartApp"     CommandName="Start" Text="Start" /></div>
<div><asp:LinkButton ID="lnkStop" runat="server" OnClick="StopApp" CommandName="Stop" Text="Stop" /></div>
</div>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Computer ID">
<ItemTemplate>
  <asp:Label runat="server" ID="lblComputerID" CssClass="linkcursor" Text='<%# DataBinder.Eval(Container, "DataItem.computerID") %>'>
  </asp:Label>
  </ItemTemplate>
</asp:TemplateField>

When a linkButton is clicked, I'd like to know on which row it was clicked. Actualy, the information i need is the Value in the ComputerID column in the same row.
How can I get it?

Thank you
0
Comment
Question by:Relegence
3 Comments
 
LVL 7

Accepted Solution

by:
skiltz earned 200 total points
Comment Utility
in the gridview set the the datakeynames to computerID

then in the rowcommand event you can get the datakey name using the e.commandArgument property

0
 

Author Comment

by:Relegence
Comment Utility
Where do I set the datakeynames? Can you please give an example?
0
 
LVL 14

Assisted Solution

by:ajitha75
ajitha75 earned 200 total points
Comment Utility
Do it like this

<asp:LinkButton ID="lnkStart" Enabled="false" runat="server" OnClick="StartApp"     CommandName="Start" Text="Start"
CommandArgument='<%# DataBinder.Eval(Container,"RowIndex")%>'
 />

and in server code
access it as below

((LinkButton)sender).CommandArgument
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Read about why website design really matters in today's demanding market.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
This video teaches users how to migrate an existing Wordpress website to a new domain.

743 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