如何使用Linkbutton运行事件

编程入门 行业动态 更新时间:2024-10-08 02:25:28
本文介绍了如何使用Linkbutton运行事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

Am试图使用Linkbutton传递多个值,并且当单击该link按钮时,它应该运行一个事件,这就是事实.请帮助.检查我的代码 以下是我的gridview中的列

Am trying to pass multiple values using a Linkbutton and when that link button is clicked it should run an event, Now thats not hapening. Plase help. Check my code Below is the column in my gridview

<Columns> <asp:TemplateField HeaderText="Cancel Appointment"> <ItemTemplate> <asp:LinkButton ID="hyperDetails" OnClick="cancel_Click" runat="server" NavigateUrl='<%# "frmFindAppointment.aspx?Fullname=" + HttpUtility.UrlEncode(Eval("Fullname").ToString())+"&EmpRecNumber="+ HttpUtility.UrlEncode(Eval("EmpRecNumber").ToString())+"&Date="+ HttpUtility.UrlEncode(Eval("Date").ToString())+"&SlotsID="+ HttpUtility.UrlEncode(Eval("SlotsID").ToString())+"&Timeslot="+ HttpUtility.UrlEncode(Eval("Timeslot").ToString()) %>' Text="Cancel Appointment" /> </ItemTemplate> </asp:TemplateField> </Columns>

现在,当我单击链接时,它应该在下面运行事件

Now when I click the link it should run the event below

public void cancel_Click(object sender, EventArgs e) { if (!IsPostBack) { if (System.Windows.Forms.MessageBox.Show("Sure want to Cancel Appointment?", "Cancel Appointment", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) == DialogResult.Yes) { systemBusinessLayer = new BusinessLayer(); systemBusinessLayer.cancelAppointmentByEmployee(Convert.ToInt32(Session["SlotID"]), Convert.ToInt32(Session["EmpRecNr"])); } } }

我该如何解决? 这些值在同一页面中传递,并在cancel_Click()事件中使用.

How can i solve this? The values are passed in the same page and are being used in the cancel_Click() event.

推荐答案

在ASPX页面中: In ASPX Page: <asp:templatefield headertext="Cancel" headerstyle-horizontalalign="Center" itemstyle-horizontalalign="Center" xmlns:asp="#unknown"> <itemtemplate> <asp:linkbutton id="CancelButton" runat="server" imageurl="~/images/Cancel.jpg" commandargument="e.Row.RowIndex.ToString()" commandname="Cancel" /> </itemtemplate> </asp:templatefield>

在CodeBehind页面

In CodeBehind page

protected void MainGridView_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { LinkButton editButton = (LinkButton)(e.Row.FindControl("CancelButton")); editButton.CommandArgument = "You Own Arguments"; //Fullname so and so } }

protected void MainGridView_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Edit") { if (System.Windows.Forms.MessageBox.Show("Sure want to Cancel Appointment?", "Cancel Appointment",System.Windows.Forms.MessageBoxButtons.YesNo,System.Windows.Forms.MessageBoxIcon.Question) == DialogResult.Yes) { systemBusinessLayer = new BusinessLayer(); systemBusinessLayer.cancelAppointmentByEmployee(Convert.ToInt32(Session["SlotID"]), Convert.ToInt32(Session["EmpRecNr"])); } } }

更多推荐

如何使用Linkbutton运行事件

本文发布于:2023-11-25 06:13:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628633.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   事件   Linkbutton

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!