Nested Parent/Child Drop Down issue

M

Me LK

I have a nested dropdown menu (size) inside a datagrid if clothing
items. It contails the child data for the datagrid. When the page
loads the correct child data is visible in each dropdown menu in each
row. So far so good

But when I choose an item in the list the incorrect size is placed
into the database. It is always the last size on the list of all
sizes, not just the sizes listed in the specific datalist of each row
but the last size of all sizes of all dropdown lists in the datagrid.

I know I am having trouble getting the correct control. It seems to be
finding a control based on row number instead of based on column. Hope
that makes sense.

Here is the code

Datagrid:

<asp:datagrid id="itemInfo" runat="server"
CssClass="DetailsProductList" AutoGenerateColumns="False" Width="525"
BorderColor="#666699" BorderStyle="Solid" BorderWidth="1px" Font-
Size="11px" Font-Names="Verdana, Arial, Helvetica, sans-serif">

<Columns>

<asp:BoundColumn DataField="strProductName" HeaderText="Item Name"></
asp:BoundColumn>


<asp:TemplateColumn>
<ItemTemplate>
<asp:DropDownList Width="100" id="ddlsizes" runat="server"
datasource='<%# Container.DataItem.CreateChildView("ProdToSizes") %>'
datatextfield="psize" datavaluefield="psize"> </asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>

<asp:LinkButton id="linkButton"
CommandArgument='<%#databinder.eval(Container.dataitem,
"intProductID") %>' Text='<%#databinder.eval(Container.dataitem,
"intProductID") %>' Runat="server"> </asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>

Code behind with relationship



' 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)

' Data for Sizes
------------------------------------------------------------------------------------
Dim connection3 As New SqlConnection(connectionString)
'Create and Initialize the command Object
Dim command3 As New SqlCommand("spGetProductSizes",
connection)
command3.CommandType = CommandType.StoredProcedure

'Add an Input Parameter
command3.Parameters.Add("@ProductCode", SqlDbType.NVarChar,
50)
command3.Parameters("@ProductCode").Value = ProductCode


Dim sizedetail As New SqlDataAdapter
sizedetail.SelectCommand = command3

'relationships--------------------------------

Dim datarelation As New DataSet
productDetail.Fill(datarelation, "products")
sizedetail.Fill(datarelation, "sizes")

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()

Dim dssizedetail As New DataSet
ColorDetail.Fill(dssizedetail)


NOW FOR THE PROBLEM!!!
--------------------------------------------------------

Protected Sub itemInfo_itemCommand(ByVal source As Object, ByVal e As
System.web.UI.WebControls.DataGridCommandEventArgs) Handles
itemInfo.ItemCommand


'The command arguement of the button that was clicked
'In the datagrid contains the productID

Dim Psize
Dim ddlPsize As DropDownList

*********BELOW THE ITEMS(1) is NOT REFFERRING TO THE CORRECT COLUMN
IN THE GRID! IT SEEMS TO BE REFERRING TO THE ROW

ddlPsize = (itemInfo.Items(1).FindControl("ddlsizes"))

*********ABOVE THE ITEMS(1) is NOT REFFERRING TO THE CORRECT COLUMN
IN THE GRID. IT SEEMS TO BE REFERRING TO THE ROW.

If Not ddlPsize Is Nothing Then

Psize = ddlPsize.SelectedItem.Value.ToString

Else
Psize = "NA"

End If


Dim intProductID As Integer = e.CommandArgument

'Add the product to the shopping cart
ShoppingCart.AddProduct(intProductID, Psize)

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top