Solved

Using a LinkButton in a gridView column

Posted on 2008-06-10
3
3,094 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

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

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmakerā€¦
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

724 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