从gridview内部的LinkButton传递值 [英] Passing values from a LinkButton inside a gridview
问题描述
早安们
我在gridview中有一个linkbutton,该linkbutton假设正在执行2个工作,第一个它应该执行一个modalpopup,第二个它应该能够将值传递给弹出窗口中的控件
它执行的唯一操作是执行弹出窗口.以下是我的链接按钮
Morning guys
I have a linkbutton inside my gridview, the linkbutton suppose to be doing 2 jobs, 1st it should execute a modalpopup and 2ndly it should be able to pass values to the controls inside the popup
The only thing it performs is to execute the popup. Below is my linkbutton
<asp:LinkButton ID="createAppointment" runat="server" PostBackUrl='<%#"frmFindAppointment.aspx?Fullname=" + HttpUtility.UrlEncode(Eval("Fullname").ToString())+"&RecordNumber="+ HttpUtility.UrlEncode(Eval("RecordNumber").ToString())+"&Date="+ HttpUtility.UrlEncode(Eval("Date").ToString())+"&SlotID="+ HttpUtility.UrlEncode(Eval("SlotID").ToString())+"&Timeslot="+ HttpUtility.UrlEncode(Eval("Timeslot").ToString())+"&EmpEmail="+ HttpUtility.UrlEncode(Eval("EmpEmail").ToString()) %>' Text="Create Appointment" />
以下是我如何接收传递的值
Below is how i recieve my passed values
if (Request.QueryString["Fullname"] != null && !string.IsNullOrEmpty(Request.QueryString["Fullname"].ToString()) || (Request.QueryString["RecordNumber"] != null && !string.IsNullOrEmpty(Request.QueryString["RecordNumber"].ToString()) || (Request.QueryString["EmpEmail"] != null && !string.IsNullOrEmpty(Request.QueryString["EmpEmail"].ToString()) ||
(Request.QueryString["Date"] != null && !string.IsNullOrEmpty(Request.QueryString["Date"].ToString())) || (Request.QueryString["SlotID"] != null && !string.IsNullOrEmpty(Request.QueryString["SlotID"].ToString())) || (Request.QueryString["Timeslot"] != null && !string.IsNullOrEmpty(Request.QueryString["Timeslot"].ToString())))))
{
string fullName = Convert.ToString((Request.QueryString["FullName"]));
Session["FullName"] = fullName;
this.txtViewStaffName.Text = Session["FullName"].ToString();
recNumber = Convert.ToInt32(Request.QueryString["RecordNumber"].ToString());
date = Request.QueryString["Date"].ToString();
slot = Convert.ToInt32(Request.QueryString["SlotID"].ToString());
Session["SlotID"] = slot;
this.ddlTimeSlots.Items.Add(Request.QueryString["Timeslot"].ToString());
Session["EmpEmail"] = (Request.QueryString["EmpEmail"].ToString());
}
现在我看到值是NULL,因为跳过了if语句.我需要帮助.
Now i see that the values are NULL because the if statement is skiped. I need help.
推荐答案
尝试使用Gridview的Row Command Event,使您的链接按钮像这样
Hi,
Try using Gridview''s Row Command Event, make your link button like this
<asp:LinkButton ID="createAppointment" runat="server" CommandArgument="<"FullName">" Text="Create Appointment" commandname="abc" />
和
在代码上写这个
if(e.CommandName ="abc")
//做您想做的事
and
on code write this
if(e.CommandName="abc")
//do what you want
如果条件如下所示,请尝试更改
try changing if condition like below
if (
(Request.QueryString["Fullname"] != null && !string.IsNullOrEmpty(Request.QueryString["Fullname"].ToString()))
||
(Request.QueryString["RecordNumber"] != null && !string.IsNullOrEmpty(Request.QueryString["RecordNumber"].ToString()))
||
(Request.QueryString["EmpEmail"] != null && !string.IsNullOrEmpty(Request.QueryString["EmpEmail"].ToString()))
||
(Request.QueryString["Date"] != null && !string.IsNullOrEmpty(Request.QueryString["Date"].ToString()))
||
(Request.QueryString["SlotID"] != null && !string.IsNullOrEmpty(Request.QueryString["SlotID"].ToString()))
||
(Request.QueryString["Timeslot"] != null && !string.IsNullOrEmpty(Request.QueryString["Timeslot"].ToString()))
)
{
}
我尝试使用它,并且效果很好.
i try with this and its working fine.
test.aspx?Fullname=test&RecordNumber=5&Date=12102010&SlotID=5&Timeslot=5&EmpEmail=test
这篇关于从gridview内部的LinkButton传递值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!