我有一个位于Emailenquiries.aspx页面的数据列表,我希望将那些被修改的数据列表值转换为另一个名为Enquirymaintenance.aspx的页面。请帮帮我..
这是我的代码
Emailenquiries.aspx(我刚把这些值夏天化为三个)
<asp:DataList ID="DataList1" runat="server" DataKeyField="PD_ID" OnItemCommand ="DataList1_OnItemCommand" DataSourceID="sdsEnquiries">
<ItemTemplate>
<h2>Enquiry details</h2>
<ul class="left patientInfo">
<li>
<label>Title</label>
<asp:Label ID="PD_TitleLabel" runat="server" Text='<%# Eval("PD_Title") %>' />
</li>
<li>
<label>First Name</label>
<asp:Label ID="PD_FirstNameLabel" runat="server" Text='<%# Eval("PD_FirstName") %>' />
</li>
<li>
<label>Last Name</label>
<asp:Label ID="PD_LastNameLabel" runat="server" Text='<%# Eval("PD_LastName") %>' />
</li>
<li>
</ul>
</ItemTemplate>
<asp:Button ID="Button1" runat="server" Text="Promote as Enquiry" CommandName ="PromoteAsEnquiry" OnClick="btnPromote_Click" CssClass="htmlbutton" />
Emailenquiries.aspx.cs
protected void DataList1_OnItemCommand(Object sender, DataListCommandEventArgs e)
{
if (e.CommandName == "PromoteAsEnquiry")
{
DataListItem row = DataList1.Items[e.Item.ItemIndex];
DropDownList ddlTitle = (DropDownList)row.FindControl("PD_TitleLabel");
Label lblFirstName = (Label)row.FindControl("PD_FirstNameLabel");
Label lblLastName = (Label)row.FindControl("PD_LastNameLabel");
Session["title"] = ddlTitle.Text;
Session["firstname"] = lblFirstName.Text;
Session["lastname"] = lblLastName.Text;
Response.Redirect("EnquiryMaintenance.aspx");
}
}
Enquirymaintenance.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
EM_ddlTitle.Text = Session["title"].ToString();
lblEM_FirstName.Text = Session["firstname"].ToString();
lblEM_LastName.Text = Session["firstname"].ToString();
}
答案 0 :(得分:0)
也许您可以使用以下方法之一:
// This is your source page
Response.Redirect("EnquiryMaintenance.aspx?objectId=" + someObjectId);
// This is your target page
string objectId = Request.QueryString["objectId"];
答案 1 :(得分:0)
我认为最好的方法,因为你已经使用了数据源,是将所选字段的密钥作为查询字符串传递(或者如果它应该被隐藏则作为发布请求),而在另一页上使用相同的数据源和排除通过参数过滤。
这样,如果将来有结构更改,则不应更改任何内容(除非数据源未采用所有值,否则应在此处添加字段)。
不要忘记在Enquirymaintenance.aspx上验证参数!
答案 2 :(得分:0)
我正在尝试第一种方法:
我创建了新的sqldatasource以传递id(newid),如下所示:
Emailenquiry.aspx
<asp:SqlDataSource ID="SqlDataSource1" runat="server"ConnectionString="<%$ ConnectionStrings:myConnectionString %>" SelectCommand="SELECT * FROM [tbl_PatientDetails_PD]LEFT JOIN [tbl_MakeAppointment_MA] ON [tbl_PatientDetails_PD].[PD_ID] = [tbl_MakeAppointment_MA].[MA_PD_ID] LEFT JOIN [tbl_ChangeAppointment_CHA] ON [tbl_PatientDetails_PD].[PD_ID] = [tbl_ChangeAppointment_CHA].[CHA_PD_ID] LEFT JOIN [tbl_CancelAppointment_CA] ON [tbl_PatientDetails_PD].[PD_ID] = [tbl_CancelAppointment_CA].[CA_PD_ID] WHERE ([PD_ID] = @PD_ID)">
<SelectParameters>
<asp:ControlParameter ControlID="lblEM_ID" Name="PD_ID" PropertyName="Text"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
lblEM_ID设置为不可见:
<asp:Label ID="lblEM_ID" runat="server" Visible="False"></asp:Label>
Emailenquiry.aspx.cs
protected void btnPromote_Click(object sender, EventArgs e)
{
Response.Redirect("EnquiryMaintenance.aspx?newid=" + lblEM_ID.Text);
}
Enquirymaintenance.aspx.cs
if(!Page.IsPostBack)
{
string objectId = Request.QueryString["newid"];
}
答案 3 :(得分:-1)
致:SonerGönül
我要做的是将所有值传递给enquirymaintenance.aspx页面。我需要提升我从emailenquiry.aspx收到的查询(数据)并将其他数据添加到数据库。我用以下代码测试了我的代码:
protected void Page_Load(object sender, EventArgs e)
{
// lblEM_Title.Text = Session["Title"].ToString();
if (Session["firstname"] != null)
{
EM_ddlTitle.Text = Session["title"].ToString();
lblEM_FirstName.Text = Session["firstname"].ToString();
lblEM_LastName.Text = Session["firstname"].ToString();
}
else {
Label2.Text = "ERROR";
}
}
我试图传递“firstname”但我收到ERROR,这意味着数据不会从emailenquiry.aspx页面传递。
致:MatíasFidemraizer
我试过这个方法..因为我需要为每个新的查询创建一个新的id ..但它不起作用:
在Emailenquiry.aspx.cs
Response.Redirect("EnquiryMaintenance.aspx?newid=" + lblEM_ID.Text);
在Emailenquiry.aspx
中<asp:Label ID="lblEM_ID" runat="server" Visible="False"></asp:Label>