Solved

Using a LinkButton in a gridView column

Posted on 2008-06-10
3
3,077 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

896 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

17 Experts available now in Live!

Get 1:1 Help Now