如何使用Linkbutton运行事件 [英] How to Run an event using Linkbutton

查看:60
本文介绍了如何使用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运行事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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