Click here to Skip to main content
15,912,897 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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

XML
<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

C#
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"]));

               }

           }
       }


How can i solve this?

The values are passed in the same page and are being used in the cancel_Click() event.
Posted
Comments
Sergey Alexandrovich Kryukov 14-Aug-11 23:39pm    
What does it mean: "run an event"?
--SA

1 solution

In ASPX Page:
C#
<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>


In CodeBehind page

C#
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
            }
        }


C#
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"]));
 }
  }
}
 
Share this answer
 
Comments
Anele Ngqandu 12-Aug-11 7:19am    
So a place where I put my code;
editButton.CommandArgument = "You Own Arguments"

I should put this code "frmFindAppointment.aspx?Fullname=" + HttpUtility.UrlEncode(Eval("Fullname").ToString())"? the code to pass values
Anele Ngqandu 12-Aug-11 7:26am    
Ok i get this error "The GridView 'grvViewAppointments' fired event RowCancelingEdit which wasn't handled. " and i cant see the RowCancelingEdit event in my code and markup.
senthil sennu 12-Aug-11 8:01am    
You should use OnRowCommand="MainGridView_RowCommand" and OnRowCreated="MainGridView_RowCreated"

For example
<asp:GridView ID="MainGridView" runat="server" OnRowCommand="MainGridView_RowCommand" OnRowCreated="MainGridView_RowCreated">
Anele Ngqandu 12-Aug-11 8:50am    
Intrestingly I stil get the same error
senthil sennu 12-Aug-11 9:06am    
Remove RowCancelingEdit event which is specified in the aspx file in GridView node. This error is due to unavailabitity of the RowCancelingEdit event in Codebehind file. Hope this helps.

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