Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 25th, 2007, 09:42 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default dropdownlist inside a datalist's itemtemplate

I followed this site and I got it to work as the site shows - http://aspalliance.com/142_Working_w...s_in_DataGrids

However, with my scenario I need to figure out how to take the ID from the datalist and pass it to my Function:

<asp:DropDownList id="ddlSizes"
            DataSource="<%# BindSize(DataBinder.Eval(Container.DataItem, "ID")) %>"

This returns a malformed syntax error for the aspx page.

Basically I'm returning a lot of data that has specific data associated with it and I want to dump that data in a DropDownList.

If it can be handled in the codebehind that would be best but when I try that I get "object reference not set to an instance of an object..." for my DDL.


Code Behind attempt:
Page_Load
list.DataSource = datalayer.GetProducts()
list.DataBind()
BindSizes(list.DataKeyField) 'list.DataKeyField is wrong... I can't figure out how to send the ID.


Private Sub BindSizes(ByVal productId As String)
        Dim connection As New OleDbConnection(connectionString)
        ' Create and initialize the command object
        Dim strSQL As String = "SELECT SizeID, ProductID, Sizes & ' - ' & Price AS Sizes, Price " & _
                                 "FROM Sizes " & _
           "WHERE (ProductID = " & productid & ")"
        Dim objCmd As New OleDbCommand(strSQL, connection)
        Dim objDR As OleDbDataReader
        Try
            connection.Open()
            objCmd.ExecuteReader(CommandBehavior.CloseConnecti on)
        Catch e As Exception
            connection.Close()
            Throw e
        End Try
        Dim myDDL As DropDownList = list.FindControl("ddlSizes")
        myDDL.DataSource = objCmd
        myDDL.DataTextField = "Sizes"
        myDDL.DataValueField = "SizeID"
        myDDL.DataBind()
    End Sub


 
Old April 26th, 2007, 04:44 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

DOH!

DataSource='<%# BindSizes(DataBinder.Eval(Container.DataItem, "ProductID")) %>'

Instead of

DataSource="<%# BindSizes(DataBinder.Eval(Container.DataItem, "ProductID")) %>"

 
Old April 26th, 2007, 05:53 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

I am trying to use code behind to make the DropDownList not visible if there is no data but I am unsure how to accomplish this. I also want to update the DataList's price value once the DrowDownList has been selected. Does anyone know of any good articles on how to accomplish this?






Similar Threads
Thread Thread Starter Forum Replies Last Post
Two DropDownList Inside a Gridview ilayaraja ASP.NET 3.5 Basics 3 December 5th, 2008 06:26 PM
DropDownList Inside a datagrid @shish ASP.NET 1.0 and 1.1 Professional 3 January 29th, 2007 07:24 PM
dropdownlist inside datagrid myunus General .NET 11 October 29th, 2006 07:37 AM
is it possilble to do logic inside an itemtemplate Raif ASP.NET 1.0 and 1.1 Professional 5 August 19th, 2004 02:20 PM
dropdownlist inside datagrid shaileshmark General .NET 5 June 27th, 2004 05:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.