Solved

Using a LinkButton in a gridView column

Posted on 2008-06-10
3
3,081 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
ID: 21749595
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
ID: 21749672
Where do I set the datakeynames? Can you please give an example?
0
 
LVL 14

Assisted Solution

by:ajitha75
ajitha75 earned 200 total points
ID: 21753918
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Where can I find... 1 28
Deploying to Azure 3 27
Select only the top record in a left join 13 34
How to create a textarea which saves text in HTML 8 33
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
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…

813 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