473,327 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

nested drop down

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("intProduc tID"),
datarelation.Tables("colors").Columns("intProductI D"))
datarelation.Relations.Add("ProdTosizes",
datarelation.Tables("products").Columns("intProduc tID"),
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>
<asp:DropDownList Width="150"
AutoPostBack="True" id="ddlcolors" runat="server" datasource='<%#
Container.DataItem.CreateChildView("ProdToColors") %>'
datatextfield="strColorID" datavaluefield="strColorID"</
asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton id="linkButton" CommandName='<
%#databinder.eval(Container.dataitem, "intProductID") %>'
CommandArgument='<%#databinder.eval(Container.data item,
"intProductID") %>' Text='<%#databinder.eval(Container.dataitem,
"intProductID") %>' Runat="server"</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>

Nov 7 '07 #1
2 1899
I narrowed down the error. Now I just need to know how to fix it.

Dim Psize
Dim ddlPsize As DropDownList
ddlPsize = (itemInfo.Items(0).FindControl("ddlsizes"))
It is choosing the first row becuase of the above code.

I tried ddlPsize =
(itemInfo.Items(itemInfo.SelectedIndex).FindContro l("ddlsizes"))

But I got this error
Index was out of range. Must be non-negative and less than the size of
the collection. Parameter name: index

Can anyone help me at this point?

Nov 7 '07 #2
LVP
check what is the SelectedIndex Value is First
If nothing is selected then it is -1 ( negative one )

Then Move on
"Me LK" <kl*****@charter.netwrote in message
news:11**********************@v29g2000prd.googlegr oups.com...
>I narrowed down the error. Now I just need to know how to fix it.

Dim Psize
Dim ddlPsize As DropDownList
ddlPsize = (itemInfo.Items(0).FindControl("ddlsizes"))
It is choosing the first row becuase of the above code.

I tried ddlPsize =
(itemInfo.Items(itemInfo.SelectedIndex).FindContro l("ddlsizes"))

But I got this error
Index was out of range. Must be non-negative and less than the size of
the collection. Parameter name: index

Can anyone help me at this point?

Nov 7 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Afkamm | last post by:
I can't get my head around them. I have two MySQL tables, one contains the categories, the other contains the posts. Each post is linked to a category. Now I'm trying to display each post with...
2
by: ehm | last post by:
I am working on creating an editable grid (for use in adding, deleting, and editing rows back to an Oracle database). I have a JSP that posts back to a servlet, which in turns posts to a WebLogic...
3
by: Tommy | last post by:
I have been working on getting nested repeaters to work for several days. When I add a repeater inside my item template i cannot see it in my code and can't set the datasource for it, etc, thus...
3
by: Don Wash | last post by:
Hi There! I have a Server-side Drop-down box in ASP.NET (VB) page. What do I do to widen the Drop down box's Pull-Down list's width? I'm not talking about the Drop-down box's width but the box...
2
by: Yoshitha | last post by:
hi I have 2 drop down lists in my application.1st list ontains itmes like java,jsp,swings,vb.net etc.2nd list contains percentage i.e it conatains the items like 50,60,70,80,90,100. i will...
1
by: David Shorthouse | last post by:
Hello folks, I just started thinking about a db-driven, 3-tier nested option menu in AJAX instead of the typical onchange --> post. I seem to have something working, but the resultant formatting...
6
by: Steve Hershoff | last post by:
Hi everyone, I've got a strange one here. There are two datagrids on my page, one nested within the other. I'll refer to them as the topmost and secondary datagrids. In the topmost...
4
by: TycoonUK | last post by:
Hi, As I do not have IE7 on my computer, I was wondering if there is a fault in my CSS Menu when using IE7. Please can someone look at my site - http://www.worldofmonopoly.co.uk and tell me...
0
by: Chris | last post by:
I have a formview that contains a "drill down" set of dropdowns. You select a team and it filters the team members drop down to show team members who belong to that team. I am acheiving this by...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.