我目前正在从事一个项目,我想在两个Web表单之间传输数据(多个客户->将一个人的ID传输到另一个表单并显示其产品)。 我对此有疑问,我的客户记录了
[弃用]不赞成在主线程上使用同步XMLHttpRequest,因为它对最终用户的体验有不利影响
这是我的代码.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="editClient.aspx.cs" Async="true" EnableEventValidation="false" Inherits="MarkUp.editClient" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>DETALII CLIENT</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<div class="table-responsive">
<asp:GridView runat="server" ID="gridProduse" HeaderStyle-BorderStyle="None" HeaderStyle-BackColor="#3366ff" HeaderStyle-ForeColor="White" AllowPaging="true" AutoGenerateColumns="true" AllowSorting="true" OnSorting="TaskGridView_Sorting" PagerSettings-Mode="NextPreviousFirstLast">
<Columns>
<asp:TemplateField HeaderText="Denumire Produs" SortExpression="NumeProdus" HeaderStyle-Width="150px">
<ItemTemplate>
<asp:HiddenField runat="server" ID="hidProdus" Value='<%#DataBinder.Eval(Container.DataItem,"ID_Produs") %>' />
<asp:Label runat="server" ID="lbNumeProdus" Text='<%#DataBinder.Eval(Container.DataItem,"NumeProdus") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Detalii" SortExpression="Detalii">
<ItemTemplate>
<asp:Label runat="server" ID="lbDetalii" Text='<%#DataBinder.Eval(Container.DataItem,"Detalii") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Nr. Bucati" SortExpression="Nr_Bucati">
<ItemTemplate>
<asp:Label runat="server" ID="lbNrBucati" Text='<%#DataBinder.Eval(Container.DataItem,"Nr_Bucati") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Data">
<ItemTemplate>
<asp:Label runat="server" ID="lbData" Text='<%#DataBinder.Eval(Container.DataItem,"DataIntrareClient") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</div>
</form>
</body>
</html>
.aspx.cs:
public partial class editClient : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
MySqlConnection con = new MySqlConnection("Server=127.0.0.1;Database=markup;Port=3306;Uid=root;Pwd=;");
MySqlCommand com = new MySqlCommand("select * from clienti_produse where ID_Client=@idclient", con);
com.Parameters.AddWithValue("@idclient",Request.QueryString["idClient]"]);
String s = Request.QueryString["idClient"];
MySqlDataAdapter da = new MySqlDataAdapter();
da.SelectCommand = com;
DataTable dt = new DataTable();
con.Open();
da.Fill(dt);
gridProduse.DataSource = dt;
gridProduse.DataBind();
con.Close();
if (!IsPostBack)
{
gridProduse.DataBind();
}
}
protected void TaskGridView_Sorting(object sender, GridViewSortEventArgs e)
{
//Retrieve the table from the session object.
DataTable tCxC = (DataTable)gridProduse.DataSource;
if (tCxC != null)
{
//Sort the data.
tCxC.DefaultView.Sort = e.SortExpression + " " + GetSortDirection(e.SortExpression);
gridProduse.DataSource = tCxC;
gridProduse.DataBind();
}
}
private string GetSortDirection(string column)
{
string sortDirection = "ASC";
string sortExpression = ViewState["SortExpression"] as string;
if (sortExpression != null)
{
if (sortExpression == column)
{
string lastDirection = ViewState["SortDirection"] as string;
if ((lastDirection != null) && (lastDirection == "ASC"))
{
sortDirection = "DESC";
}
}
}
ViewState["SortDirection"] = sortDirection;
ViewState["SortExpression"] = column;
return sortDirection;
}
}
我的请求链接如下:http://localhost:8057/editClient?idClient=34
在此先感谢您的帮助,非常感谢。