如何在用户单击Gridview中的图像按钮时传递id [英] How to Pass a id when user click a imagebutton in Gridview

查看:55
本文介绍了如何在用户单击Gridview中的图像按钮时传递id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<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在gridview中有很多作业列表..我需要在用户点击特定作业图像按钮时传递一个id ...我该怎么做?



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?

推荐答案

添加commandargument属性

使用OnCommand而不是OnClick



Add commandargument property
Use OnCommand instead of OnClick

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







在ImageButton1_Command事件中,您获得ID




In ImageButton1_Command event you get ID

int ID = Convert.ToInt32(e.CommandArgument);


您可以将Id设置为Imagebutton的CommandArguement属性:



< asp :ImageButton ID =ImageButton1OnClick =ImageButton1_ClickImageUrl =〜/ images / apply.pngrunat =serverCommandArguement ='<%#Eval(Id)%>'/>



你可以在服务器端获得Id Imagebutton点击事件:





ImageButton ib =(ImageButton)Sender;

Int Id = int.Parse(ib.CommandArguement);
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);






您可以使用 GridView_RowCommand()来完成。请点击以下链接此处



谢谢
Hi,

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

Thanks


这篇关于如何在用户单击Gridview中的图像按钮时传递id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆