M
Me LK
I have a set of drop downs nested in a datagrid. Each drop down is a
size or color for an item. Each row of the grid has a button which
leads to a cart. When a user selects something from the first row or
nested drop downs the page refreshes, the correct item is selected in
the list and the and upon clicking the add to cart button the correct
choices show up in the database. When a person selects something from
a row other then the first row of the grid the page refreshes, the
correct item shows in the list but when the item is added to the
database the data from the top row of the grid is added.
I would love some help on this one.
Code is as follows
If Not IsPostBack Then
' Data for products
--------------------------------------------------
Dim connection As New SqlConnection(connectionString)
'Create and Initialize the command Object
Dim command As New SqlCommand("new_GetChildDetail",
connection)
command.CommandType = CommandType.StoredProcedure
'Add an Input Parameter
command.Parameters.Add("@ProductCode", SqlDbType.NVarChar,
50)
command.Parameters("@ProductCode").Value = ProductCode
Dim productDetail As New SqlDataAdapter
productDetail.SelectCommand = command
Dim dsProductDetail As New DataSet
productDetail.Fill(dsProductDetail)
' ProductList.DataSource = dsProductDetail
' ProductList.DataBind()
'Data for Colors---------------------------------------------------
Dim connection2 As New SqlConnection(connectionString)
'Create and Initialize the command Object
Dim command2 As New SqlCommand("spGetProductColor2",
connection2)
command2.CommandType = CommandType.StoredProcedure
'Add an Input Parameter
command2.Parameters.Add("@StrProductCode",
SqlDbType.NVarChar, 50)
command2.Parameters("@StrProductCode").Value =
strProductCode
Dim ColorDetail As New SqlDataAdapter
ColorDetail.SelectCommand = command2
Dim dsColorDetail As New DataSet
ColorDetail.Fill(dsColorDetail)
(duplicate coding for size omited)
'relationships--------------------------------
Dim datarelation As New DataSet
ColorDetail.Fill(datarelation, "colors")
productDetail.Fill(datarelation, "products")
sizedetail.Fill(datarelation, "sizes")
datarelation.Relations.Add("ProdToColors",
datarelation.Tables("products").Columns("intProductID"),
datarelation.Tables("colors").Columns("intProductID"))
datarelation.Relations.Add("ProdTosizes",
datarelation.Tables("products").Columns("intProductID"),
datarelation.Tables("sizes").Columns("intProductID"))
Cache.Insert("datarelation", datarelation)
itemInfo.DataSource = datarelation.Tables("products")
itemInfo.DataBind()
End If
Protected Sub itemInfo_itemCommand(ByVal source As Object, ByVal e As
System.web.UI.WebControls.DataGridCommandEventArgs) Handles
itemInfo.ItemCommand
'
COLOR--------------------------------------------------------
Dim Color
Dim ddlColors As DropDownList
ddlColors = (itemInfo.Items(0).FindControl("ddlColors"))
If Not ddlColors Is Nothing Then
Color = ddlColors.SelectedItem.Value.ToString
Else
Color = "NA"
End If
'PRODUCTS----------------------------------------------------------------------
Dim intProductID As Integer = e.CommandArgument
'Add the product to the shopping cart
ShoppingCart.AddProduct(intProductID, Psize, Color)
Dim redirect = "shoppingcart.aspx"
Response.Redirect(redirect)
End Sub
_______________________________________________________________________________
Code for grid
<asp:datagrid id="itemInfo" runat="server" AutoGenerateColumns="False" <Columns>
<asp:BoundColumn DataField="strProductName" HeaderText="Item Name"> </
asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<aspropDownList Width="150"
AutoPostBack="True" id="ddlcolors" runat="server" datasource='<%#
Container.DataItem.CreateChildView("ProdToColors") %>'
datatextfield="strColorID" datavaluefield="strColorID"> </
aspropDownList>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton id="linkButton" CommandName='<
%#databinder.eval(Container.dataitem, "intProductID") %>'
CommandArgument='<%#databinder.eval(Container.dataitem,
"intProductID") %>' Text='<%#databinder.eval(Container.dataitem,
"intProductID") %>' Runat="server"> </asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
size or color for an item. Each row of the grid has a button which
leads to a cart. When a user selects something from the first row or
nested drop downs the page refreshes, the correct item is selected in
the list and the and upon clicking the add to cart button the correct
choices show up in the database. When a person selects something from
a row other then the first row of the grid the page refreshes, the
correct item shows in the list but when the item is added to the
database the data from the top row of the grid is added.
I would love some help on this one.
Code is as follows
If Not IsPostBack Then
' Data for products
--------------------------------------------------
Dim connection As New SqlConnection(connectionString)
'Create and Initialize the command Object
Dim command As New SqlCommand("new_GetChildDetail",
connection)
command.CommandType = CommandType.StoredProcedure
'Add an Input Parameter
command.Parameters.Add("@ProductCode", SqlDbType.NVarChar,
50)
command.Parameters("@ProductCode").Value = ProductCode
Dim productDetail As New SqlDataAdapter
productDetail.SelectCommand = command
Dim dsProductDetail As New DataSet
productDetail.Fill(dsProductDetail)
' ProductList.DataSource = dsProductDetail
' ProductList.DataBind()
'Data for Colors---------------------------------------------------
Dim connection2 As New SqlConnection(connectionString)
'Create and Initialize the command Object
Dim command2 As New SqlCommand("spGetProductColor2",
connection2)
command2.CommandType = CommandType.StoredProcedure
'Add an Input Parameter
command2.Parameters.Add("@StrProductCode",
SqlDbType.NVarChar, 50)
command2.Parameters("@StrProductCode").Value =
strProductCode
Dim ColorDetail As New SqlDataAdapter
ColorDetail.SelectCommand = command2
Dim dsColorDetail As New DataSet
ColorDetail.Fill(dsColorDetail)
(duplicate coding for size omited)
'relationships--------------------------------
Dim datarelation As New DataSet
ColorDetail.Fill(datarelation, "colors")
productDetail.Fill(datarelation, "products")
sizedetail.Fill(datarelation, "sizes")
datarelation.Relations.Add("ProdToColors",
datarelation.Tables("products").Columns("intProductID"),
datarelation.Tables("colors").Columns("intProductID"))
datarelation.Relations.Add("ProdTosizes",
datarelation.Tables("products").Columns("intProductID"),
datarelation.Tables("sizes").Columns("intProductID"))
Cache.Insert("datarelation", datarelation)
itemInfo.DataSource = datarelation.Tables("products")
itemInfo.DataBind()
End If
Protected Sub itemInfo_itemCommand(ByVal source As Object, ByVal e As
System.web.UI.WebControls.DataGridCommandEventArgs) Handles
itemInfo.ItemCommand
'
COLOR--------------------------------------------------------
Dim Color
Dim ddlColors As DropDownList
ddlColors = (itemInfo.Items(0).FindControl("ddlColors"))
If Not ddlColors Is Nothing Then
Color = ddlColors.SelectedItem.Value.ToString
Else
Color = "NA"
End If
'PRODUCTS----------------------------------------------------------------------
Dim intProductID As Integer = e.CommandArgument
'Add the product to the shopping cart
ShoppingCart.AddProduct(intProductID, Psize, Color)
Dim redirect = "shoppingcart.aspx"
Response.Redirect(redirect)
End Sub
_______________________________________________________________________________
Code for grid
<asp:datagrid id="itemInfo" runat="server" AutoGenerateColumns="False" <Columns>
<asp:BoundColumn DataField="strProductName" HeaderText="Item Name"> </
asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<aspropDownList Width="150"
AutoPostBack="True" id="ddlcolors" runat="server" datasource='<%#
Container.DataItem.CreateChildView("ProdToColors") %>'
datatextfield="strColorID" datavaluefield="strColorID"> </
aspropDownList>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton id="linkButton" CommandName='<
%#databinder.eval(Container.dataitem, "intProductID") %>'
CommandArgument='<%#databinder.eval(Container.dataitem,
"intProductID") %>' Text='<%#databinder.eval(Container.dataitem,
"intProductID") %>' Runat="server"> </asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>