gpt4 book ai didi

c# - 在循环中使用 FindControl 获取以编程方式添加的文本框的值

转载 作者:太空宇宙 更新时间:2023-11-03 16:21:59 27 4
gpt4 key购买 nike

我有一个绑定(bind)到 DropDownList 的 GridView。当 DropDownList 的索引更改时,GridView 由 SQL 查询更新。 GridView 的单元格中的值被转换为标签,并以编程方式添加一个文本框。单击按钮时,标签和文本框的值循环通过,然后提交到购物车。

我无法将 TextBox 的值放入我的循环中。 FindControl 找不到TextBox 的ID?我认为这与以编程方式添加 TextBox 有关吗?

请原谅我的无知和编码方法...我才接触 ASP 一年。

protected void Page_Load(object sender, EventArgs e) {
NPBasePage _bp = (NPBasePage) Page;
string myUserID = _bp.UserID;
UserIDLabel.Text = myUserID;
if (Page.IsPostBack) {} else {}
}

protected void RapidOrderEntry_RowDataBound(object sender, GridViewRowEventArgs e) {
if (e.Row.RowType == DataControlRowType.DataRow) {
foreach(TableCell c in e.Row.Cells) {
TextBox l = new TextBox();
l.ID = "QuantityTextBox";
l.Text = "0";
l.CssClass = "QuantityTextBox";
Label b = new Label();
b.ID = "PartNumberLabel";
b.CssClass = "labelNone";
Label x = new Label();
x.Text = " ";
x.CssClass = "null";
b.Text = c.Text;
if (c.Text == " ") {
c.Controls.Add(x);
} else {
c.Controls.Add(l);
c.Controls.Add(b);
}
}
}
}

protected void AddTheseItemsToMyShoppingBagButton_Click(object sender, EventArgs e) {
NPBasePage _bp = (NPBasePage) Page;
NPOrder order = new NPOrder(_bp.UserID, _bp.SessionID);
if (!order.Initialized) {
order.CreateDefaultOrder(_bp.UserID, _bp.AccountID, _bp.SessionID);
}
for (int x = 0; x < RapidOrderEntry.Rows.Count; x++) {
for (int y = 0; y < RapidOrderEntry.Rows[x].Cells.Count; y++) {
NPOrderDetail newdet = order.AddPart((RapidOrderEntry.Rows[x].Cells[y].Text), Int32.Parse(((TextBox)RapidOrderEntry.Rows[x].Cells[y].FindControl("QuantityTextBox")).Text), _bp.CatalogCode, "", _bp.PriceList, 0, NPConnection.GetConfigDB("Commerce", "CalculationUoM"));
}
}
Response.Redirect("/commerce/cart.aspx");
}

我确定问题出在这个和我的循环中:

Int32.Parse(((TextBox)RapidOrderEntry.Rows[x].Cells[y].FindControl("QuantityTextBox")).Text)

返回的错误是“对象引用未设置到对象的实例。”如果我像这样手动将整数设置为 1:

NPOrderDetail newdet = order.AddPart((RapidOrderEntry.Rows[x].Cells[y].Text), 1, _bp.CatalogCode, "", _bp.PriceList, 0, NPConnection.GetConfigDB("Commerce", "CalculationUoM"));

它就像一个魅力。但客户需要能够输入自己的数量。

编辑

这是我的完整代码——希望对您有所帮助。

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="netpoint.api" %>
<%@ Import Namespace="netpoint.api.catalog" %>
<%@ Import Namespace="netpoint.api.commerce" %>
<%@ Import Namespace="netpoint.classes" %>
<%@ Import Namespace="netpoint.api.data" %>

<%@ Page language="c#" Inherits="netpoint.classes.NPBasePage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link rel="Shortcut Icon" href="/favicon.ico">
<title>Rapid Order Entry</title>
<link href="../../assets/common/themes/2011/css/partner.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="../../assets/common/themes/2011/js/common.js"></script>

<style>
h2 {
font-size: 15px;
color: #2D210B;
font-weight: bolder;
margin-bottom: 0px;
padding-bottom: 0px;
}
p {
font-family: Arial, Verdana, Helvetica, sans-serif;
font-size: 11px;
line-height: 14px;
}
.red {
background-color: #F66;
color: #333;
}
.yellow {
background-color: #FFDC78;
color: #333;
}
.green {
background-color: #B4DCB4;
color: #333;
}
.null {
background-color: #CCC;
}
#RapidOrderEntry th {
width: 35px;
height: 35px;
}
.color {
font-weight: bold;
width: 67px;
}
.labelNone {
display: none;
}
.QuantityTextBox {
width: 20px;
height: 20px;
text-align: center;
}
</style>



<script runat="server">

protected void Page_Load(object sender, EventArgs e) {
NPBasePage _bp = (NPBasePage) Page;
string myUserID = _bp.UserID;
UserIDLabel.Text = myUserID;

if (Page.IsPostBack) {}
else {}
}

protected void RapidOrderEntry_RowCreated(object sender, GridViewRowEventArgs e) {
if (e.Row.RowType == DataControlRowType.DataRow)
{
int cellIndex = 0;
foreach (TableCell c in e.Row.Cells)
{
TextBox l = new TextBox();
l.ID = string.Format("QuantityTextBox_{0}_{1}", e.Row.RowIndex, cellIndex);
l.Text = "0";
l.CssClass = "QuantityTextBox";
Label b = new Label();
b.ID = string.Format("PartNumberLabel_{0}_{1}", e.Row.RowIndex, cellIndex);
b.CssClass = "labelNone";
Label x = new Label();
x.Text = "&nbsp;";
x.CssClass = "null";
b.Text = c.Text;
if (c.Text == "&nbsp;")
{
c.Controls.Add(x);
}
else
{
c.Controls.Add(l);
c.Controls.Add(b);
}

cellIndex++;
}
}
}

protected void AddTheseItemsToMyShoppingBagButton_Click(object sender, EventArgs e) {



NPBasePage _bp = (NPBasePage) Page;
NPOrder order = new NPOrder(_bp.UserID, _bp.SessionID);
if (!order.Initialized) {
order.CreateDefaultOrder(_bp.UserID, _bp.AccountID, _bp.SessionID);
}
for (int x = 0; x < RapidOrderEntry.Rows.Count; x++) {
for (int y = 0; y < RapidOrderEntry.Rows[x].Cells.Count; y++) {

TextBox tb = (TextBox)RapidOrderEntry.Rows[x].Cells[y].FindControl(string.Format("QuantityTextBox_{0}_{1}", x, y));
int t = Int32.Parse((tb).Text);
NPOrderDetail newdet = order.AddPart((RapidOrderEntry.Rows[x].Cells[y].Text), t, _bp.CatalogCode, "", _bp.PriceList, 0, NPConnection.GetConfigDB("Commerce", "CalculationUoM"));
}
}
Response.Redirect("/commerce/cart.aspx");
}



protected void PLMDropDownAlpha_SelectedIndexChanged(object sender, EventArgs e) {
RapidOrderEntryDS.SelectParameters.Clear();
PLMDropDownNum.SelectedIndex = 0;
string PartNo = PLMDropDownAlpha.SelectedValue;
RapidOrderEntryDS.SelectCommand = "SELECT Color, [1] [XS], [2] [S], [3] [M], [4] [L], [5] [XL], [6] [2XL], [7] [3XL], [8] [4XL], [9] [5XL], [10] [6XL], [11] [LT], [12] [XLT], [13] [2XLT], [14] [3XLT], [15] [4XLT], [16] [5XLT], [17] [6XLT], [18] [OSFM], [19] [ADJ] FROM (SELECT CASE SUBSTRING(PartsMaster.PartNo, CHARINDEX('-', PartsMaster.PartNo) + 1, CHARINDEX('-', PartsMaster.PartNo, CHARINDEX('-', PartsMaster.PartNo) + 1) - (CHARINDEX('-', PartsMaster.PartNo) + 1)) WHEN 'SDL' THEN 'Saddle' WHEN 'TBC' THEN 'Tobacco' WHEN 'APN' THEN 'Aspen' WHEN 'ASP' THEN 'Asphalt' WHEN 'BLK' THEN 'Black' WHEN 'FKH' THEN 'FldKhaki' WHEN 'GVL' THEN 'Gravel' WHEN 'GRV' THEN 'Gravel' WHEN 'MOS' THEN 'Moss' WHEN 'NVY' THEN 'Navy' WHEN 'SAW' THEN 'Sawdust' WHEN 'OS' THEN 'OSFM' WHEN 'BAR' THEN 'Barley' WHEN 'SGE' THEN 'Sage' WHEN 'STN' THEN 'Stone' WHEN 'MOC' THEN 'Mocha' WHEN 'DSK' THEN 'Dusk' WHEN 'ROS' THEN 'Rose' WHEN 'APL' THEN 'Apple' WHEN 'PER' THEN 'Persimon' WHEN 'SND' THEN 'Sand' WHEN 'MUS' THEN 'Mustard' WHEN 'GRN' THEN 'Green' WHEN 'BRN' THEN 'Brown' WHEN '0HD' THEN 'CamoHD' WHEN 'WHE' THEN 'Wheat' WHEN '0M4' THEN 'CamoMax4' WHEN 'OLV' THEN 'Olive' WHEN '0HG' THEN 'CamoHDG' WHEN 'CHR' THEN 'Charcoal' WHEN 'CAN' THEN 'Canyon' WHEN 'GRY' THEN 'Gray' WHEN 'RED' THEN 'Red' WHEN 'BLZ' THEN 'Blaze' WHEN 'MAR' THEN 'Maroon' WHEN 'WLD' THEN 'PPK' WHEN 'PPK' THEN 'OSFM' WHEN 'NGT' THEN 'Night' WHEN 'SLR' THEN 'Solar' WHEN 'WDF' THEN 'Wildfire' WHEN '0AP' THEN 'CamoAP' WHEN 'DOX' THEN 'DrkOxford' WHEN 'SUN' THEN 'Sunset' WHEN 'MDN' THEN 'Midnight' WHEN 'SHD' THEN 'Shadow' WHEN 'PTL' THEN 'Petal' WHEN 'LTN' THEN 'LtTan' WHEN 'CHC' THEN 'Chocolate' WHEN 'SMK' THEN 'Smoke' WHEN 'FTG' THEN 'Fatigue' WHEN 'CAC' THEN 'Cactus' WHEN 'ROP' THEN 'Rope' WHEN 'STL' THEN 'Steel' WHEN 'CLY' THEN 'Clay' WHEN 'KHA' THEN 'Khaki' WHEN 'CHA' THEN 'Charcoal' WHEN 'ERH' THEN 'Earth' WHEN 'MAZ' THEN 'Maize' WHEN 'PNK' THEN 'Pink' WHEN 'CSN' THEN 'Chestnut' WHEN 'FTG' THEN 'Fatigue' WHEN 'INK' THEN 'Ink' WHEN 'PTY' THEN 'Putty' WHEN 'BRK' THEN 'Bark' WHEN 'DWD' THEN 'Driftwood' WHEN 'EVG' THEN 'Evergreen' WHEN 'RWD' THEN 'Redwood' WHEN 'TWN' THEN 'Tawny' WHEN 'SLT' THEN 'Slate' WHEN 'TPE' THEN 'Taupe' WHEN 'TAN' THEN 'Tan' WHEN 'CHL' THEN 'Chili' WHEN 'ELM' THEN 'Elm' WHEN 'LAK' THEN 'Lake' WHEN 'DUN' THEN 'Dune' WHEN 'LDN' THEN 'Loden' WHEN 'STR' THEN 'Stream' WHEN 'SNS' THEN 'Sandston' WHEN 'DNM' THEN 'Denim' WHEN 'PEP' THEN 'Pepper' WHEN 'DBR' THEN 'DKBrown' WHEN 'MUD' THEN 'Mud' WHEN 'BRZ' THEN 'Bronze' WHEN 'GPH' THEN 'Graphite' WHEN 'WHT' THEN 'White' WHEN 'SPC' THEN 'Spice' WHEN 'DGR' THEN 'Dark Green' WHEN '0PA' THEN 'Pink Camo AP' WHEN 'PNE' THEN 'Pine' WHEN 'LGN' THEN 'Lagoon' WHEN 'OPA' THEN 'CamoPnkAP' WHEN '0AB' THEN 'CamoAPBlk' WHEN '0AE' THEN 'CamoAPEvg' WHEN 'CBL' THEN 'Colbalt' ELSE substring(PartsMaster.PartNo, 6, 3) END [Color], CASE WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = 'XS' THEN 1 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = 'S' THEN 2 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = 'M' THEN 3 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = 'L' THEN 4 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = 'XL' THEN 5 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = '2XL' THEN 6 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = '3L' THEN 7 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = '4XL' THEN 8 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = '5XL' THEN 9 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = '6XL' THEN 10 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = 'LT' THEN 11 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = 'XLT' THEN 12 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = '2XLT' THEN 13 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = '3XLT' THEN 14 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = '4XLT' THEN 15 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = '5XLT' THEN 16 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = '6XLT' THEN 17 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = 'OSFM' THEN 18 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = 'ADJ' THEN 19 ELSE '20' END [size], CASE WHEN PartsInventory.OnHand > 0 THEN PartsMaster.PartNo ELSE NULL END [stock_value] FROM PartsAttribute INNER JOIN PartsMaster ON PartsAttribute.PartNo = PartsMaster.PartNo LEFT OUTER JOIN PartsInventory ON PartsMaster.PartNo = PartsInventory.PartNo WHERE (LEN(PartsMaster.PartNo) > 9) AND (PartsMaster.ProductLinePartNo LIKE '" + PartNo + "') AND ((PartsAttribute.AttributeCode = N'size' OR PartsAttribute.AttributeCode = N'color')) AND PartsInventory.WarehouseCode IN ('01') AND (PartsAttribute.PartNo = PartsMaster.PartNo) AND (PartsMaster.PartNo = PartsInventory.PartNo) AND (PartsAttribute.PartNo = PartsInventory.PartNo) AND (PartsInventory.OnHand IS NOT NULL OR PartsAttribute.AttributeCode IS NOT NULL OR PartsMaster.PartNo IS NOT NULL OR PartsAttribute.Dimension1 IS NOT NULL)) AS source PIVOT (min(stock_value) FOR [Size] IN ([1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19])) AS pivoted";
RapidOrderEntry.DataBind();
}
protected void PLMDropDownNum_SelectedIndexChanged(object sender, EventArgs e) {
RapidOrderEntryDS.SelectParameters.Clear();
PLMDropDownAlpha.SelectedIndex = 0;
string PartNo = PLMDropDownNum.SelectedValue;
RapidOrderEntryDS.SelectCommand = "SELECT Color, [1] [XS], [2] [S], [3] [M], [4] [L], [5] [XL], [6] [2XL], [7] [3XL], [8] [4XL], [9] [5XL], [10] [6XL], [11] [LT], [12] [XLT], [13] [2XLT], [14] [3XLT], [15] [4XLT], [16] [5XLT], [17] [6XLT], [18] [OSFM], [19] [ADJ] FROM (SELECT CASE SUBSTRING(PartsMaster.PartNo, CHARINDEX('-', PartsMaster.PartNo) + 1, CHARINDEX('-', PartsMaster.PartNo, CHARINDEX('-', PartsMaster.PartNo) + 1) - (CHARINDEX('-', PartsMaster.PartNo) + 1)) WHEN 'SDL' THEN 'Saddle' WHEN 'TBC' THEN 'Tobacco' WHEN 'APN' THEN 'Aspen' WHEN 'ASP' THEN 'Asphalt' WHEN 'BLK' THEN 'Black' WHEN 'FKH' THEN 'FldKhaki' WHEN 'GVL' THEN 'Gravel' WHEN 'GRV' THEN 'Gravel' WHEN 'MOS' THEN 'Moss' WHEN 'NVY' THEN 'Navy' WHEN 'SAW' THEN 'Sawdust' WHEN 'OS' THEN 'OSFM' WHEN 'BAR' THEN 'Barley' WHEN 'SGE' THEN 'Sage' WHEN 'STN' THEN 'Stone' WHEN 'MOC' THEN 'Mocha' WHEN 'DSK' THEN 'Dusk' WHEN 'ROS' THEN 'Rose' WHEN 'APL' THEN 'Apple' WHEN 'PER' THEN 'Persimon' WHEN 'SND' THEN 'Sand' WHEN 'MUS' THEN 'Mustard' WHEN 'GRN' THEN 'Green' WHEN 'BRN' THEN 'Brown' WHEN '0HD' THEN 'CamoHD' WHEN 'WHE' THEN 'Wheat' WHEN '0M4' THEN 'CamoMax4' WHEN 'OLV' THEN 'Olive' WHEN '0HG' THEN 'CamoHDG' WHEN 'CHR' THEN 'Charcoal' WHEN 'CAN' THEN 'Canyon' WHEN 'GRY' THEN 'Gray' WHEN 'RED' THEN 'Red' WHEN 'BLZ' THEN 'Blaze' WHEN 'MAR' THEN 'Maroon' WHEN 'WLD' THEN 'PPK' WHEN 'PPK' THEN 'OSFM' WHEN 'NGT' THEN 'Night' WHEN 'SLR' THEN 'Solar' WHEN 'WDF' THEN 'Wildfire' WHEN '0AP' THEN 'CamoAP' WHEN 'DOX' THEN 'DrkOxford' WHEN 'SUN' THEN 'Sunset' WHEN 'MDN' THEN 'Midnight' WHEN 'SHD' THEN 'Shadow' WHEN 'PTL' THEN 'Petal' WHEN 'LTN' THEN 'LtTan' WHEN 'CHC' THEN 'Chocolate' WHEN 'SMK' THEN 'Smoke' WHEN 'FTG' THEN 'Fatigue' WHEN 'CAC' THEN 'Cactus' WHEN 'ROP' THEN 'Rope' WHEN 'STL' THEN 'Steel' WHEN 'CLY' THEN 'Clay' WHEN 'KHA' THEN 'Khaki' WHEN 'CHA' THEN 'Charcoal' WHEN 'ERH' THEN 'Earth' WHEN 'MAZ' THEN 'Maize' WHEN 'PNK' THEN 'Pink' WHEN 'CSN' THEN 'Chestnut' WHEN 'FTG' THEN 'Fatigue' WHEN 'INK' THEN 'Ink' WHEN 'PTY' THEN 'Putty' WHEN 'BRK' THEN 'Bark' WHEN 'DWD' THEN 'Driftwood' WHEN 'EVG' THEN 'Evergreen' WHEN 'RWD' THEN 'Redwood' WHEN 'TWN' THEN 'Tawny' WHEN 'SLT' THEN 'Slate' WHEN 'TPE' THEN 'Taupe' WHEN 'TAN' THEN 'Tan' WHEN 'CHL' THEN 'Chili' WHEN 'ELM' THEN 'Elm' WHEN 'LAK' THEN 'Lake' WHEN 'DUN' THEN 'Dune' WHEN 'LDN' THEN 'Loden' WHEN 'STR' THEN 'Stream' WHEN 'SNS' THEN 'Sandston' WHEN 'DNM' THEN 'Denim' WHEN 'PEP' THEN 'Pepper' WHEN 'DBR' THEN 'DKBrown' WHEN 'MUD' THEN 'Mud' WHEN 'BRZ' THEN 'Bronze' WHEN 'GPH' THEN 'Graphite' WHEN 'WHT' THEN 'White' WHEN 'SPC' THEN 'Spice' WHEN 'DGR' THEN 'Dark Green' WHEN '0PA' THEN 'Pink Camo AP' WHEN 'PNE' THEN 'Pine' WHEN 'LGN' THEN 'Lagoon' WHEN 'OPA' THEN 'CamoPnkAP' WHEN '0AB' THEN 'CamoAPBlk' WHEN '0AE' THEN 'CamoAPEvg' WHEN 'CBL' THEN 'Colbalt' ELSE substring(PartsMaster.PartNo, 6, 3) END [Color], CASE WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = 'XS' THEN 1 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = 'S' THEN 2 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = 'M' THEN 3 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = 'L' THEN 4 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = 'XL' THEN 5 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = '2XL' THEN 6 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = '3L' THEN 7 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = '4XL' THEN 8 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = '5XL' THEN 9 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = '6XL' THEN 10 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = 'LT' THEN 11 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = 'XLT' THEN 12 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = '2XLT' THEN 13 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = '3XLT' THEN 14 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = '4XLT' THEN 15 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = '5XLT' THEN 16 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = '6XLT' THEN 17 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = 'OSFM' THEN 18 WHEN PartsAttribute.AttributeCode = 'size' AND PartsAttribute.Dimension1 = 'ADJ' THEN 19 ELSE '20' END [size], CASE WHEN PartsInventory.OnHand > 0 THEN PartsMaster.PartNo ELSE NULL END [stock_value] FROM PartsAttribute INNER JOIN PartsMaster ON PartsAttribute.PartNo = PartsMaster.PartNo LEFT OUTER JOIN PartsInventory ON PartsMaster.PartNo = PartsInventory.PartNo WHERE (LEN(PartsMaster.PartNo) > 9) AND (PartsMaster.ProductLinePartNo LIKE '" + PartNo + "') AND ((PartsAttribute.AttributeCode = N'size' OR PartsAttribute.AttributeCode = N'color')) AND PartsInventory.WarehouseCode IN ('01') AND (PartsAttribute.PartNo = PartsMaster.PartNo) AND (PartsMaster.PartNo = PartsInventory.PartNo) AND (PartsAttribute.PartNo = PartsInventory.PartNo) AND (PartsInventory.OnHand IS NOT NULL OR PartsAttribute.AttributeCode IS NOT NULL OR PartsMaster.PartNo IS NOT NULL OR PartsAttribute.Dimension1 IS NOT NULL)) AS source PIVOT (min(stock_value) FOR [Size] IN ([1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19])) AS pivoted";
RapidOrderEntry.DataBind();
}
protected void ViewShoppingBag_Click(object sender, EventArgs e) {
Response.Redirect("/commerce/cart.aspx/");
}
</script>



</head>
<body>
<form id="form1" runat="server">

<div align="center" style="font-family: Arial, Helvetica, sans-serif;">

<p>You can use these dropdown lists to quickly jump to all of one product's sizes and colors.</p>


<asp:DropDownList ID="PLMDropDownAlpha" runat="server" AutoPostBack="True"
DataSourceID="ListByPLMDSAlpha" DataTextField="PartName"
DataValueField="PartNo"
onselectedindexchanged="PLMDropDownAlpha_SelectedIndexChanged" Width="225px" >
</asp:DropDownList>

&nbsp;&nbsp;

<asp:DropDownList ID="PLMDropDownNum" runat="server" AutoPostBack="True"
DataSourceID="ListByPLMDSNum" DataTextField="PartName"
DataValueField="PartNo"
onselectedindexchanged="PLMDropDownNum_SelectedIndexChanged" Width="225px" >
</asp:DropDownList>

<asp:SqlDataSource ID="ListByPLMDSNum" runat="server"
ConnectionString="<%$ ConnectionStrings:connString %>"
SelectCommand="
SELECT 'disabled' AS PartNo, ' Products by Part Number ' AS PartName, NULL AS PartCode
UNION ALL
SELECT PartNo, CASE
WHEN PartNo LIKE '%-OD-%' THEN left(PartCode,4) + ' - ' + PartName + ' ' + 'Camo'
WHEN PartNo LIKE '%-AP-%' THEN left(PartCode,4) + ' - ' + PartName + ' ' + 'Camo'
WHEN PartNo LIKE '%-0HD-%' THEN left(PartCode,4) + ' - ' + PartName + ' ' + 'Camo'
WHEN PartNo LIKE '%-0M4-%' THEN left(PartCode,4) + ' - ' + PartName + ' ' + 'Camo'
ELSE left(PartCode,4) + ' - ' + PartName END PartName, PartCode
FROM PartsMaster
WHERE (ProductLineFlag = 'Y') AND (StaticThumbnail <> '')
ORDER BY PartCode
">
</asp:SqlDataSource>

<asp:SqlDataSource ID="ListByPLMDSAlpha" runat="server"
ConnectionString="<%$ ConnectionStrings:connString %>"
SelectCommand="
SELECT 'disabled' AS PartNo, ' Products by Part Name ' AS PartName
UNION ALL
SELECT PartNo, CASE
WHEN PartNO LIKE '%-OD-%' THEN PartName + ' ' + 'Camo'
WHEN PartNO LIKE '%-AP-%' THEN PartName + ' ' + 'Camo'
WHEN PartNO LIKE '%-0HD-%' THEN PartName + ' ' + 'Camo'
WHEN PartNO LIKE '%-0M4-%' THEN PartName + ' ' + 'Camo'
ELSE PartName END
FROM PartsMaster
WHERE (ProductLineFlag = 'Y') AND (StaticThumbnail <> '')
ORDER BY PartName
">
</asp:SqlDataSource>


<br />
<br />
<br />


</asp:SqlDataSource>
<asp:GridView ID="RapidOrderEntry" runat="server" datasourceid="RapidOrderEntryDS" OnRowCreated="RapidOrderEntry_RowCreated" autogeneratecolumns="False" style="width:790px;margin:0 auto;text-align:center;">
<Columns>
<asp:BoundField DataField="Color" HeaderText="" itemstyle-cssclass="color" />
<asp:BoundField DataField="XS" HeaderText="XS" />
<asp:BoundField DataField="S" HeaderText="S" />
<asp:BoundField DataField="M" HeaderText="M" />
<asp:BoundField DataField="L" HeaderText="L" />
<asp:BoundField DataField="XL" HeaderText="XL" />
<asp:BoundField DataField="2XL" HeaderText="2XL" />
<asp:BoundField DataField="3XL" HeaderText="3XL" />
<asp:BoundField DataField="4XL" HeaderText="4XL" />
<asp:BoundField DataField="5XL" HeaderText="5XL" />
<asp:BoundField DataField="6XL" HeaderText="6XL" />
<asp:BoundField DataField="LT" HeaderText="LT" />
<asp:BoundField DataField="XLT" HeaderText="XLT" />
<asp:BoundField DataField="2XLT" HeaderText="2XLT" />
<asp:BoundField DataField="3XLT" HeaderText="3XLT" />
<asp:BoundField DataField="4XLT" HeaderText="4XLT" />
<asp:BoundField DataField="5XLT" HeaderText="5XLT" />
<asp:BoundField DataField="6XLT" HeaderText="6XLT" />
<asp:BoundField DataField="OSFM" HeaderText="OSFM" />
<asp:BoundField DataField="ADJ" HeaderText="ADJ" />
</Columns>
<EmptyDataTemplate>
<div style="height:200px;" align="center">
<h2 ID="EmptyDataTemplateOn" style="font-weight:normal;position:relative;top:80px;color:#999;display:none;">The Inventory Matrix for this item is currently unavailable due to insufficient stock information.<br />Item inventories are updated frequently. Please try again later.</h2>
<h2 ID="EmptyDataTemplateOff" style="font-weight:normal;position:relative;top:85px;color:#999;">Please choose an item.</h2>
</div>
</EmptyDataTemplate>
</asp:GridView>
<asp:SqlDataSource ID="RapidOrderEntryDS" runat="server" ConnectionString="<%$ ConnectionStrings:connString %>" />
<SelectParameters>
<asp:Parameter Name="PartNo" Type="String" />
</SelectParameters>
</asp:SqlDataSource>


<br />
<asp:Button ID="AddTheseItemsToMyShoppingBagButton" runat="server" Text="Add These Items to My Order" onclick="AddTheseItemsToMyShoppingBagButton_Click" />

<asp:Label ID="UserIDLabel" runat="server" Visible="false"></asp:Label>

</div>
</form>
</body>
</html>

最佳答案

我认为生成文本框字段或标签是更好的主意 using TemplateFields.

编辑

您可以在 RowCreated 事件处理程序中创建控件,使用唯一名称命名控件:

protected void RapidOrderEntry_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int cellIndex = 0;
foreach (TableCell c in e.Row.Cells)
{
TextBox l = new TextBox();
l.ID = string.Format("QuantityTextBox_{0}_{1}", e.Row.RowIndex, cellIndex);
l.Text = "0";
l.CssClass = "QuantityTextBox";
Label b = new Label();
b.ID = string.Format("PartNumberLabel_{0}_{1}", e.Row.RowIndex, cellIndex);
b.CssClass = "labelNone";
Label x = new Label();
x.Text = "&nbsp;";
x.CssClass = "null";
b.Text = c.Text;
if (c.Text == "&nbsp;")
{
c.Controls.Add(x);
}
else
{
c.Controls.Add(l);
c.Controls.Add(b);
}

cellIndex++;
}
}
}

然后您可以像这样检索控件:

 protected void AddTheseItemsToMyShoppingBagButton_Click(object sender, EventArgs e)
{
for (int x = 0; x < RapidOrderEntry.Rows.Count; x++)
{
for (int y = 0; y < RapidOrderEntry.Rows[x].Cells.Count; y++)
{
TextBox tb = (TextBox)RapidOrderEntry.Rows[x].Cells[y].FindControl(string.Format("QuantityTextBox_{0}_{1}", x, y));
int t = Int32.Parse((tb).Text);
}
}
}

关于c# - 在循环中使用 FindControl 获取以编程方式添加的文本框的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13634758/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com