我有一个大数据库,其中每一行都有一个唯一的文档代码,然后是每个数量和每个成员/非成员的价格。即每个数量有2个价格一个会员价格和一个非会员价格。(会张贴一张照片,但显然我没有足够的声誉)。
无论如何,我使用如下所示的选择命令从数据库中提取值:
<asp:SqlDataSource id="sds_docReader" ConnectionString="<%$ ConnectionStrings:constr %>"
runat="server" SelectCommand="
SELECT '--Please Select--' AS fld_DocCode, '' AS myValue, 0 as myorder
UNION
SELECT fld_DocCode, (CAST([fld_MemCost25] AS varchar(10)) + '^^' + CAST([fld_NonMemCost25] AS varchar(10)) + '@@' + CAST([fld_MemCost50] AS varchar(10)) + '^^' + CAST([fld_NonMemCost50] AS varchar(10)) + '@@' + CAST([fld_MemCost75] AS varchar(10)) + '^^' + CAST([fld_NonMemCost75] AS varchar(10)) + '@@' + CAST([fld_MemCost100] AS varchar(10)) + '^^' + CAST([fld_NonMemCost100] AS varchar(10)) + '@@' + CAST([fld_MemCost200] AS varchar(10)) + '^^' + CAST([fld_NonMemCost200] AS varchar(10)) + '@@' + CAST([fld_MemCost300] AS varchar(10)) + '^^' + CAST([fld_NonMemCost300] AS varchar(10)) + '@@' + CAST([fld_MemCost400] AS varchar(10)) + '^^' + CAST([fld_NonMemCost400] AS varchar(10)) + '@@' + CAST([fld_MemCost500] AS varchar(10)) + '^^' + CAST([fld_NonMemCost500] AS varchar(10))) AS myValue,
1 as myorder
FROM [tbl_DocData]
ORDER BY myorder, fld_DocCode " />
并将其推入我的下拉列表的值字段中,以在页面后端获得类似的内容:
value="60.50^^75.50@@121.00^^151.00@@135.75^^181.50@@181.00^^242.00@@362.00^^484.00@@453.00^^633.00@@484.00^^724.00@@605.00^^905.00"
所以这就是我目前正在尝试做的事情:
在每个 @@ 处拆分 value 字段以获取价格对数组:
"[member_price]^^[non_memberprice]"
使用.selectedindex
来自数量下拉列表,我从刚刚制作的数组中拉出正确的一对。
然后最后一步是将价格对数组price1^^price2
从price1, price2
然后取决于他们是否选中了一个框以表明他们是会员,我将采用数组的 0 索引成员(价格对左侧的内容)作为会员价格,或者 1非成员价格的数组的索引成员。
这是我试图用来执行上述操作的代码:
Protected Sub btn_Calc_Command(sender As Object, e As System.Web.UI.WebControls.CommandEventArgs)
'get the left side of the price pairs (members)
Dim side As Integer = 0
If cb_CCTAMember.Checked = True Then
'get the right side (non members)
side = 1
End If
If AC1.SelectedItem.Text <> "--Please Select--" And Quan1.SelectedItem.Text <> "0" Then
'we calculate
'get right hidden value string
Dim costs As String = AC1.SelectedItem.Value
'split by quantity to get price pairs
Dim costarray As Array
costarray = costs.Split("@@")
'get right pair
Dim pair As String = costarray(Quan1.SelectedIndex - 1)
'split the pair
Dim sprice As Array
sprice = pair.Split("^^")
'show cost as the right value
Cost1.Value = sprice(side)
End If
End Sub
所以目前它有效,但仅适用于其他所有值。即它适用于 25 但不适用于 50,适用于 75 但不适用于 100。
我是否遗漏了任何明显的/关于可能出错的任何想法/关于获得相同结果的替代方法的想法。
干杯