我正在重新创建一个多部分表单,但这个问题专门针对一个页面,其中有人注册可以标记他们可能拥有或增长的商品(如果有的话)。你可以在我的ASPX和ASPX.CS中看到我们迄今为止如何完成它(主要是利用类和一些ajax / javascript)。现在我们正在用PHP重新创建系统,我正在考虑更好(也许更简单是一个更好的词)方法来做到这一点。目前,商品列表是从SQL表中提取的,每个商品旁边都会显示一个下拉菜单(取决于它的测量单位 - EX:Acre,Flock,Head等)。在加入成员选择他的庄稼之后,他们将与他/她的成员ID和所述商品的数量一起致力于不同的桌子。见下文:
问题: 有什么,如果有的话,是用PHP做的更好的方法吗?
感谢您的时间=)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="commodities.aspx.cs" Inherits="Secure_commodities" MasterPageFile="~/secure/joinfb.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="content" Runat="Server">
<style type="text/css">
collapsePanel {
background-color:white;
overflow:hidden;
}
collapsePanelHeader{
width:100%;
height:30px;
border-color: Red;
color:#FFF;
font-weight:bold;
}
.panelImage{
vertical-align:baseline;
}
</style>
<ajaxToolkit:ToolkitScriptManager ID="tk1" runat="server" EnablePartialRendering="true" />
<asp:UpdatePanel ID="up1" runat="server">
<ContentTemplate>
<p class="formHeading"><b>Member Commodities</b></p>
<p>
<label>
Do you include any of the following production practices in your operation?
</label>
</p>
<table width="50%" cellpadding="2" cellspacing="2">
<tr>
<td>
<asp:CheckBox ID="chkOCC" runat="server" Text="Organic Crop Certification" />
</td>
<td>
<asp:CheckBox ID="chkUSDA" runat="server" Text="USDA Conservation Program" />
</td>
</tr>
</table>
<br/>
<p class="formHeading">
<asp:Panel ID="pnl1" runat="server">
<asp:Image ID="img1" runat="server" CssClass="panelImage" /> <asp:LinkButton ID="lnk1" runat="server" Text="Dairy/Livestock/Poultry" Font-Size="Medium" /> <asp:Label ID="lbl1" runat="server" />
</asp:Panel>
<%--<asp:ImageButton ID="Image1" runat="server" ImageUrl="~/images/bg-menu-main.png" AlternateText="(Show Details...)"/> --%>
<%--<asp:Label ID="Label1" runat="server">(Show Details...)</asp:Label></p>--%>
<asp:Panel ID="Panel1" runat="server" CssClass="collapsePanel" Height="0">
<asp:datalist id="dtlList1" DataKeyField="CMDY_Code" Width="100%" RepeatColumns="3" runat="server" OnItemDataBound="Bind_Unit_1"
CellPadding="1" CellSpacing="1" >
<ItemTemplate>
<table width="100%">
<tr>
<td style="width: auto" align="left" >
<asp:CheckBox Runat="server" ID="chk1" AutoPostBack="true"/>
</td>
<td style="width: 45%" align="left">
<asp:Label ID="lblTitle1" Runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Commodity") %>' />
</td>
<td style="width: 50%" align="left">
<asp:DropDownList ID="ddl1" Runat="server" CssClass="input" AutoPostBack="true" OnSelectedIndexChanged="dlQuantityChanged1" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:datalist>
</asp:Panel>
<ajaxToolkit:CollapsiblePanelExtender ID="CollapsiblePanelExtender0" runat="Server"
TargetControlID="Panel1"
ExpandControlID="pnl1"
CollapseControlID="pnl1"
Collapsed="True"
SuppressPostBack="false"
ImageControlID="img1" CollapsedImage="http://test.com/images/expand_blue.jpg" ExpandedImage="../images/collapse_blue.jpg"
TextLabelID="lbl1" CollapsedText=" " ExpandedText=" "
/>
<p class="formHeading">
<asp:Panel ID="pnl2" runat="server">
<asp:Image ID="img2" runat="server" CssClass="panelImage" /> <asp:LinkButton ID="lnk2" runat="server" Text="Field Crops" Font-Size="Medium" /> <asp:Label ID="lbl2" runat="server" />
</asp:Panel>
<asp:Panel ID="Panel2" runat="server" CssClass="collapsePanel" Height="0">
<asp:datalist id="dtlList2" DataKeyField="CMDY_Code" Width="100%" RepeatColumns="3" runat="server" OnItemDataBound="Bind_Unit_2"
CellPadding="1" CellSpacing="1" >
<ItemTemplate>
<table width="100%">
<tr>
<td style="width: auto" align="left" >
<asp:CheckBox Runat="server" ID="chk1" AutoPostBack="true"/>
</td>
<td style="width: 45%" align="left">
<asp:Label ID="lblTitle1" Runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Commodity") %>' />
</td>
<td style="width: 50%" align="left">
<asp:DropDownList ID="ddl1" Runat="server" CssClass="input" AutoPostBack="true" OnSelectedIndexChanged="dlQuantityChanged2" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:datalist>
</asp:Panel>
<ajaxToolkit:CollapsiblePanelExtender ID="CollapsiblePanelExtender1" runat="Server"
TargetControlID="Panel2"
ExpandControlID="pnl2"
CollapseControlID="pnl2"
Collapsed="True"
SuppressPostBack="false"
ImageControlID="img2" CollapsedImage="http://test.com/images/expand_blue.jpg" ExpandedImage="../images/collapse_blue.jpg"
TextLabelID="lbl2" CollapsedText=" " ExpandedText=" "
/>
<p class="formHeading">
<asp:Panel ID="pnl3" runat="server">
<asp:Image ID="img3" runat="server" CssClass="panelImage"/> <asp:LinkButton ID="lnk3" runat="server" Text="Horticulture/Forestry" Font-Size="Medium" /> <asp:Label ID="lbl3" runat="server" />
</asp:Panel>
<asp:Panel ID="Panel3" runat="server" CssClass="collapsePanel" Height="0">
<asp:datalist id="dtlList3" DataKeyField="CMDY_Code" Width="100%" RepeatColumns="3" runat="server" OnItemDataBound="Bind_Unit_3"
CellPadding="1" CellSpacing="1" >
<ItemTemplate>
<table width="100%">
<tr>
<td style="width: auto" align="left" >
<asp:CheckBox Runat="server" ID="chk1" AutoPostBack="true" />
</td>
<td style="width: 45%" align="left">
<asp:Label ID="lblTitle1" Runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Commodity") %>' />
</td>
<td style="width: 50%" align="left">
<asp:DropDownList ID="ddl1" Runat="server" CssClass="input" AutoPostBack="true" OnSelectedIndexChanged="dlQuantityChanged3" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:datalist>
</asp:Panel>
<ajaxToolkit:CollapsiblePanelExtender ID="CollapsiblePanelExtender2" runat="Server"
TargetControlID="Panel3"
ExpandControlID="pnl3"
CollapseControlID="pnl3"
Collapsed="True"
SuppressPostBack="false"
ImageControlID="img3" CollapsedImage="http://test.com/images/expand_blue.jpg" ExpandedImage="../images/collapse_blue.jpg"
TextLabelID="lbl3" CollapsedText=" " ExpandedText=" "
/>
<p class="formHeading">
<asp:Panel ID="pnl4" runat="server">
<asp:Image ID="img4" runat="server" CssClass="panelImage"/> <asp:LinkButton ID="lnk4" runat="server" Text="Trees/Vines" Font-Size="Medium" /> <asp:Label ID="lbl4" runat="server" />
</asp:Panel>
<asp:Panel ID="Panel4" runat="server" CssClass="collapsePanel" Height="0">
<asp:datalist id="dtlList4" DataKeyField="CMDY_Code" Width="100%" RepeatColumns="3" runat="server" OnItemDataBound="Bind_Unit_4"
CellPadding="1" CellSpacing="1" >
<ItemTemplate>
<table width="100%">
<tr>
<td style="width: auto" align="left" >
<asp:CheckBox Runat="server" ID="chk1" AutoPostBack="true" />
</td>
<td style="width: 45%" align="left">
<asp:Label ID="lblTitle1" Runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Commodity") %>' />
</td>
<td style="width: 50%" align="left">
<asp:DropDownList ID="ddl1" Runat="server" CssClass="input" AutoPostBack="true" OnSelectedIndexChanged="dlQuantityChanged4" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:datalist>
</asp:Panel>
<ajaxToolkit:CollapsiblePanelExtender ID="CollapsiblePanelExtender3" runat="Server"
TargetControlID="Panel4"
ExpandControlID="pnl4"
CollapseControlID="pnl4"
Collapsed="True"
SuppressPostBack="false"
ImageControlID="img4" CollapsedImage="http://test.com/images/expand_blue.jpg" ExpandedImage="../images/collapse_blue.jpg"
TextLabelID="lbl4" CollapsedText=" " ExpandedText=" "
/>
<p class="formHeading">
<asp:Panel ID="pnl5" runat="server">
<asp:Image ID="img5" runat="server" CssClass="panelImage"/> <asp:LinkButton ID="lnk5" runat="server" Text="Vegetables" Font-Size="Medium" /> <asp:Label ID="lbl5" runat="server" />
</asp:Panel>
<asp:Panel ID="Panel5" runat="server" CssClass="collapsePanel" Height="0">
<asp:datalist id="dtlList5" DataKeyField="CMDY_Code" Width="100%" RepeatColumns="3" runat="server" OnItemDataBound="Bind_Unit_5"
CellPadding="1" CellSpacing="1" >
<ItemTemplate>
<table width="100%">
<tr>
<td style="width: auto" align="left" >
<asp:CheckBox Runat="server" ID="chk1" AutoPostBack="true" />
</td>
<td style="width: 45%" align="left">
<asp:Label ID="lblTitle1" Runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Commodity") %>' />
</td>
<td style="width: 50%" align="left">
<asp:DropDownList ID="ddl1" Runat="server" CssClass="input" AutoPostBack="true" OnSelectedIndexChanged="dlQuantityChanged5" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:datalist>
</asp:Panel>
<ajaxToolkit:CollapsiblePanelExtender ID="CollapsiblePanelExtender4" runat="Server"
TargetControlID="Panel5"
ExpandControlID="pnl5"
CollapseControlID="pnl5"
Collapsed="True"
SuppressPostBack="false"
ImageControlID="img5" CollapsedImage="http://test.com/images/expand_blue.jpg" ExpandedImage="../images/collapse_blue.jpg"
TextLabelID="lbl5" CollapsedText=" " ExpandedText=" "
/>
<p>
<asp:Button ID="btnNext" runat="server" Text="Next" OnClick="btnNext_OnClick" />
</p>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using TESTReg;
public partial class Secure_commodities : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Load_DList();
if (Request.QueryString["Mode"] == "Edit")
{
// populate each CMDY
Membership Member = new Membership();
Member = (Membership)Session.Contents["Membership"];
Load_CMDY(dtlList1, Member, CollapsiblePanelExtender0);
Load_CMDY(dtlList2, Member, CollapsiblePanelExtender1);
Load_CMDY(dtlList3, Member, CollapsiblePanelExtender2);
Load_CMDY(dtlList4, Member, CollapsiblePanelExtender3);
Load_CMDY(dtlList5, Member, CollapsiblePanelExtender4);
//List<Commodity> list = new List<Commodity>();
//for (int i = 0; i < Member.Commodities.Count; i++)
//{
// list.Add(Member.Commodities[i]);
//}
//dlChildren.DataSource = list;
////dlChildren.DataBind();
//foreach (DataListItem li in dlChildren.Items)
//{
// TextBox tFname = (TextBox)(li.FindControl("txtChildFName"));
// TextBox tLname = (TextBox)(li.FindControl("txtChildLName"));
// TextBox tDOB = (TextBox)(li.FindControl("txtChildDOB"));
// tFname.Text = Member.Dependent[li.ItemIndex].FirstName;
// tLname.Text = Member.Dependent[li.ItemIndex].LastName;
// tDOB.Text = Member.Dependent[li.ItemIndex].DOB;
//}
//ddlNumChild.ClearSelection();
//ddlNumChild.Items.FindByValue(Member.Dependent.Count.ToString()).Selected = true;
}
}
}
private void Load_CMDY(DataList dl, Membership Member, AjaxControlToolkit.CollapsiblePanelExtender cp)
{
for (int i = 0; i < Member.Commodities.Count; i++)
{
foreach (DataListItem li in dl.Items)
{
CheckBox _chk = (CheckBox)(li.FindControl("chk1"));
DropDownList _ddl = (DropDownList)(li.FindControl("ddl1"));
if (Member.Commodities[i].Cmdy_Code == dl.DataKeys[li.ItemIndex].ToString())
{
_chk.Checked = Member.Commodities[i].SelectedItem;
_ddl.ClearSelection();
_ddl.Items.FindByValue(Member.Commodities[i].Unit_Value).Selected = true;
cp.Collapsed = false;
break;
}
}
}
}
private void Load_DList()
{
string sSQL;
sSQL = "SELECT CMDY_CODE, Commodity, Category FROM _WJ_TBL_Commodity WHERE Category='Dairy/Livestock/Poultry' ORDER BY Commodity";
System.Data.DataSet ds = new System.Data.DataSet();
ds = Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteDataset(System.Configuration.ConfigurationManager.ConnectionStrings["JoinFB_Conn"].ConnectionString,
System.Data.CommandType.Text, sSQL);
dtlList1.DataSource = ds;
dtlList1.DataBind();
sSQL = "SELECT CMDY_CODE, Commodity, Category FROM _WJ_TBL_Commodity WHERE Category='Field Crops' ORDER BY Commodity";
ds = new System.Data.DataSet();
ds = Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteDataset(System.Configuration.ConfigurationManager.ConnectionStrings["JoinFB_Conn"].ConnectionString,
System.Data.CommandType.Text, sSQL);
dtlList2.DataSource = ds;
dtlList2.DataBind();
sSQL = "SELECT CMDY_CODE, Commodity, Category FROM _WJ_TBL_Commodity WHERE Category='Horticulture/Forestry' ORDER BY Commodity";
ds = new System.Data.DataSet();
ds = Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteDataset(System.Configuration.ConfigurationManager.ConnectionStrings["JoinFB_Conn"].ConnectionString,
System.Data.CommandType.Text, sSQL);
dtlList3.DataSource = ds;
dtlList3.DataBind();
sSQL = "SELECT CMDY_CODE, Commodity, Category FROM _WJ_TBL_Commodity WHERE Category='Trees/Vines' ORDER BY Commodity";
ds = new System.Data.DataSet();
ds = Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteDataset(System.Configuration.ConfigurationManager.ConnectionStrings["JoinFB_Conn"].ConnectionString,
System.Data.CommandType.Text, sSQL);
dtlList4.DataSource = ds;
dtlList4.DataBind();
sSQL = "SELECT CMDY_CODE, Commodity, Category FROM _WJ_TBL_Commodity WHERE Category='Vegetables' ORDER BY Commodity";
ds = new System.Data.DataSet();
ds = Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteDataset(System.Configuration.ConfigurationManager.ConnectionStrings["JoinFB_Conn"].ConnectionString,
System.Data.CommandType.Text, sSQL);
dtlList5.DataSource = ds;
dtlList5.DataBind();
}
protected void dlQuantityChanged1(object sender, EventArgs e)
{
DropDownList _dl = (DropDownList)sender;
DataListItem _dlItem = (DataListItem)_dl.NamingContainer;
// get id of row
CheckBox _chk = (CheckBox)_dlItem.FindControl("chk1");
CheckCMDY(_chk, _dl);
}
protected void dlQuantityChanged2(object sender, EventArgs e)
{
DropDownList _dl = (DropDownList)sender;
DataListItem _dlItem = (DataListItem)_dl.NamingContainer;
// get id of row
CheckBox _chk = (CheckBox)_dlItem.FindControl("chk1");
CheckCMDY(_chk, _dl);
}
protected void dlQuantityChanged3(object sender, EventArgs e)
{
DropDownList _dl = (DropDownList)sender;
DataListItem _dlItem = (DataListItem)_dl.NamingContainer;
// get id of row
CheckBox _chk = (CheckBox)_dlItem.FindControl("chk1");
CheckCMDY(_chk, _dl);
}
protected void dlQuantityChanged4(object sender, EventArgs e)
{
DropDownList _dl = (DropDownList)sender;
DataListItem _dlItem = (DataListItem)_dl.NamingContainer;
// get id of row
CheckBox _chk = (CheckBox)_dlItem.FindControl("chk1");
CheckCMDY(_chk, _dl);
}
protected void dlQuantityChanged5(object sender, EventArgs e)
{
DropDownList _dl = (DropDownList)sender;
DataListItem _dlItem = (DataListItem)_dl.NamingContainer;
// get id of row
CheckBox _chk = (CheckBox)_dlItem.FindControl("chk1");
CheckCMDY(_chk, _dl);
}
private void CheckCMDY(CheckBox chk, DropDownList dl)
{
if (dl.SelectedIndex > 0)
chk.Checked = true;
}
protected void Bind_Unit_1(object sender, DataListItemEventArgs e)
{
Bind_DDL_Unit(e, dtlList1, "ddl1");
}
protected void Bind_Unit_2(object sender, DataListItemEventArgs e)
{
Bind_DDL_Unit(e, dtlList2, "ddl1");
}
protected void Bind_Unit_3(object sender, DataListItemEventArgs e)
{
Bind_DDL_Unit(e, dtlList3, "ddl1");
}
protected void Bind_Unit_4(object sender, DataListItemEventArgs e)
{
Bind_DDL_Unit(e, dtlList4, "ddl1");
}
protected void Bind_Unit_5(object sender, DataListItemEventArgs e)
{
Bind_DDL_Unit(e, dtlList5, "ddl1");
}
protected void Bind_DDL_Unit(DataListItemEventArgs e, DataList dtlList, string cmdy_ddl)
{
string sSQL;
DropDownList ddl;
int x;
sSQL = "select DISTINCT m.Unit_CODE FROM _WJ_TBL_Unit m, _WJ_TBL_Commodity s WHERE s.CMDY_CODE=@CMDY_CODE and m.unit_Code=s.unit_Code";
// Retrieve Unit Code first
x = Convert.ToInt32(Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteScalar(ConfigurationManager.ConnectionStrings["JoinFB_Conn"].ConnectionString,
System.Data.CommandType.Text, sSQL, new SqlParameter("@CMDY_CODE", dtlList.DataKeys[dtlList.Items.Count])));
if (x > 0)
{
sSQL = "SELECT Unit, Unit_Value FROM _WJ_TBL_Unit WHERE Unit_Code=@Unit_Code";
DataSet ds = new DataSet();
ds = Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteDataset(ConfigurationManager.ConnectionStrings["JoinFB_Conn"].ConnectionString,
System.Data.CommandType.Text, sSQL, new SqlParameter("@Unit_Code", x));
ddl = (DropDownList)(e.Item.FindControl(cmdy_ddl));
ddl.DataSource = ds;
ddl.DataTextField = "Unit";
ddl.DataValueField = "Unit_Value";
ddl.DataBind();
}
}
protected void btnNext_OnClick(object sender, EventArgs e)
{
TESTReg.Membership MemberInfo = new TESTReg.Membership();
MemberInfo = (TESTReg.Membership)Session.Contents["Membership"];
//MemberInfo.CMDY.Clear();
//MemberInfo.Produce.Clear();
MemberInfo.Commodities.Clear();
// Process Datalist
ProcessCMDY(dtlList1, MemberInfo, "ddl1", "chk1", "lblTitle1");
ProcessCMDY(dtlList2, MemberInfo, "ddl1", "chk1", "lblTitle1");
ProcessCMDY(dtlList3, MemberInfo, "ddl1", "chk1", "lblTitle1");
ProcessCMDY(dtlList4, MemberInfo, "ddl1", "chk1", "lblTitle1");
ProcessCMDY(dtlList5, MemberInfo, "ddl1", "chk1", "lblTitle1");
if (chkOCC.Checked)
MemberInfo.Organic_Crop_Cert = true;
else
MemberInfo.Organic_Crop_Cert = false;
if (chkUSDA.Checked)
MemberInfo.USDA_Cons_Prog = true;
else
MemberInfo.USDA_Cons_Prog = false;
Session.Contents["Membership"] = MemberInfo;
if (Request.QueryString["Mode"] == "Edit")
Response.Redirect("confirmation.aspx");
else
Response.Redirect("Payment.aspx");
}
private void ProcessCMDY(DataList dl, TESTReg.Membership MemberInfo, string ddlist, string chkbox, string lbel)
{
// Saves commodity checked
foreach (DataListItem di in dl.Items)
{
DropDownList ddl;
CheckBox chk;
Label lbl;
ddl = (DropDownList)(di.FindControl(ddlist));
chk = (CheckBox)(di.FindControl(chkbox));
lbl = (Label)(di.FindControl(lbel));
if (chk.Checked)
{
TESTReg.Commodity Commodities = new TESTReg.Commodity();
//MemberInfo.CMDY.Add(dl.DataKeys[di.ItemIndex]);
//MemberInfo.Produce.Add(ddl.SelectedItem.Value);
Commodities.Cmdy_Code = dl.DataKeys[di.ItemIndex].ToString();
Commodities.Unit_Value = Convert.ToString(ddl.SelectedItem.Value);
Commodities.Unit_Amt = ddl.SelectedItem.Text;
Commodities.Cmdy = lbl.Text;
Commodities.SelectedItem = chk.Checked;
MemberInfo.Commodities.Add(Commodities);
}
}
//string t1;
//string t2;
//for (int i = 0; i < MemberInfo.Commodities.Count; i++)
//{
// t1 = MemberInfo.Commodities[i].Cmdy;
// t2 = MemberInfo.Commodities[i].Unit_Amt;
//}
//return MemberInfo;
}
}