Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ASP
<asp:GridView ID="GridView1" GridLines="None" BorderStyle="None" runat="server" Width="100%" AutoGenerateColumns="False">
<Columns >
<asp:TemplateField ControlStyle-BorderStyle="None">
<ItemTemplate>
<table class="Panel ArticleSummariesPanel ViewCategoryArticleSummariesPanel" border="0" width="100%">
<tbody>
<tr>
<td height="98" class="normaltext">
<div class="Item_knock">
<span ><a href="JobInterview_Details.aspx?WID=<%#Eval("WalkinID")%>" target="_blank" class="jobbigtext"><%# Eval("Walkin_Title") %>--Exp.[<%#Eval("Exp")%>]</a></span>
<div class="Details"><strong><%#Eval("Company_Name")%> </strong> <br /><strong>Skills :</strong><%#Eval("Skills")%></div>
<div class="Content_knock">
<table cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="Content_knock" width="850" valign="top" align="left">
<strong>Job Location :</strong><%# Eval("LocationName")%></td>
<td class="Content_knock" width="550" valign="top" align="left"></td>
<td>
<asp:ImageButton ID="ImageButton1" OnClick="ImageButton1_Click" ImageUrl="~/images/apply.png" runat="server" /></td>
</tr></tbody>
</table></div></div></td>
</tr></tbody></table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>


I have a lot of jobs list in gridview..I need to pass a id when user click a particular job imagebutton...How can i do that?
Posted
Updated 14-Aug-13 1:40am
v3
Comments
[no name] 14-Aug-13 7:35am    
Hv you tried anything?

Add commandargument property
Use OnCommand instead of OnClick

C#
<asp:imagebutton id="ImageButton1" oncommand="ImageButton1_Command" imageurl="~/images/apply.png" runat="server" commandargument="<%#Eval("ID")  />



In ImageButton1_Command event you get ID
C#
int ID = Convert.ToInt32(e.CommandArgument);
 
Share this answer
 
v2
You can set Id to Imagebutton's CommandArguement Property:

<asp:ImageButton ID="ImageButton1" OnClick="ImageButton1_Click" ImageUrl="~/images/apply.png" runat="server" CommandArguement='<%# Eval("Id")%>' />

You can get Id on server side Imagebutton click event :


ImageButton ib = (ImageButton)Sender;
Int Id =int.Parse(ib.CommandArguement);
 
Share this answer
 
Hi,

You can do it using the GridView_RowCommand(). Follow the following link here.

Thanks
 
Share this answer
 
Very simple you can give a commandname to the image button and code on the GridView_RowCommand event where you can also find the control that cantains the id field or if you using datakeys then still you can find datakey very easily....
 
Share this answer
 
Use CommandArgument attribute of the ImageButton to set the value and use gridView's RowCommand event to track which button is clicked (using EventArgument value).
 
Share this answer
 
Example of gridview rowcommand on Button Click [^]
Above link will guide you how to work with grid view command
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900