I'd like to have a datagrid with several template columns each with its own databound listbox. Each of these would then AutoPostBack on change and would update a bit of example text. The listboxes themselves would only have to be created on page load and would also be within an "if NOT isPostBack" statement. I've created a mock of this as can be seen here:<BR><BR>http://216.87.15.155/datagrid.gif<BR><BR>It seems like this must be possible, but everytime I attempt to bind my data to a listbox it says the listbox isn't declared (because it's within a template column of the datagrid i'm assuming.)<BR><BR>Please say it's doable!
<BR><BR>])ryHey Dry,<BR><BR>Here are a few links that have some great code examples:<BR><BR>http://www.dotnetjunkies.com/tutorials.aspx?tutorialid=77<BR><BR>http://www.dotnetjunkies.com/tutorials.aspx?tutorialid=86<BR><BR>I've had to bind controls within a datagrid, and I've been doing it from the html view, so if you're trying from teh code behind that may be the cause? Something to check out anyway<BR><BR>Hope this helped.<BR>
<BR><BR>JackBasically the listbox is one level deeper than the current variable area. Therefore you must declare a variable that references the listbox<BR><BR>In the onItemDataBound procedure<BR>you need to declare a local variable for the listbox<BR><BR>Public sub item_OnItemDataBound(sender As Object , e As System.Web.UI.WebControls.DataGridItemEventArgs)<BR><BR>Dim ddlStates As DropDownList<BR>ddlStates = CType(e.Item.FindControl("ddlStates"), DropDownList)<BR>ddlStates.DataSource = ...<BR><BR>THey T, I've tried what you suggested, but keep getting the following error when I attempt to set the dataSource:<BR><BR>System.NullReferenceException: Object reference not set to an instance of an object.<BR><BR>Here is what I've got for the sub:<BR><BR>Public Sub bindLists(sender AS Object , e AS DataGridItemEventArgs) <BR><BR>dim lstFF AS DropDownList<BR>lstFF = cType(e.Item.FindControl("lstFontFams"), DropDownList)<BR><BR>dim FFComm AS new SqlCommand("SELECT styleFontFamID,fontFamily FROM wsStyleFontFams ORDER BY fontFamily", objConn)<BR>lstFF.DataSource = FFComm.ExecuteReader(CommandBehavior.CloseConnecti on)<BR>lstFF.DataBind()<BR><BR>end sub<BR><BR>And here is the dropdown:<BR><BR><BR><asp
ropDownList id="lstFontFams" runat="server" DataTextField="fontFamily" DataValueField="styleFontFamID" AutoPostBack="True" /><BR><BR>Any ideas?<BR><BR>Thanks,<BR><BR>])ry<BR>thanks jack, i'll definately check out the tutorials.I think you need to ignore the rows that arent in the dataset(header and footer)<BR> 'ignore row if it is not a datarow<BR> itemType = CType(e.Item.ItemType, ListItemType)<BR> If (itemType = ListItemType.Header) Or (itemType = ListItemType.Footer) Or (itemType = ListItemType.Separator) Then<BR> Return<BR> End If<BR><BR>I have listed my complete onitemdatabound for you to see how I implemented it.<BR><BR>The basic concept is for each item it can have multiple colors so I put the color in a drop down box, if it only has one color just show it as a label, and use set value of the dropdownlist to the sku which is what makes the item unique.<BR><BR><BR>Public sub item_OnItemDataBound(sender As Object , e As System.Web.UI.WebControls.DataGridItemEventArgs)<BR> Dim lblLPrice As Label<BR> Dim lblPrice As Label<BR> Dim pnum As String<BR> Dim size As String<BR> Dim price As Double<BR> Dim itemType As ListItemType<BR> Dim oUtil As Utility<BR> Dim MyList As DropDownList<BR> Dim lblColor As Label<BR> Dim MyItem as ListItem = New ListItem()<BR> oUtil = New Utility()<BR> 'ignore row if it is not a datarow<BR> itemType = CType(e.Item.ItemType, ListItemType)<BR> If (itemType = ListItemType.Header) Or (itemType = ListItemType.Footer) Or (itemType = ListItemType.Separator) Then<BR> Return<BR> End If<BR> 'set cell to no wrap<BR> e.Item.Cells.Item(0).Wrap="false"<BR> 'display price, display old price with a stirke through if it is greater than price<BR> lblLPrice = CType(e.Item.FindControl("lblLPrice"), Label)<BR> lblPrice = CType(e.Item.FindControl("lblPrice"), Label)<BR> lblLPrice.Text=System.String.Format("{0:c}", e.Item.dataitem("price"))<BR> IF e.Item.dataitem("list_price") <> e.Item.dataitem("price") THEN<BR> lblPrice.Visible=true<BR> lblPrice.Text = "<BR>" & System.String.Format("{0:c}", e.Item.dataitem("price"))<BR> lblLPrice.Text = "<S>" & System.String.Format("{0:c}", e.Item.dataitem("list_price")) & "</S>"<BR> END IF<BR> Dim description As String<BR> Dim prod As String<BR> description = e.Item.dataitem("description")<BR> prod = e.Item.dataitem("prod")<BR> pnum = e.Item.dataitem("prodnum")<BR> size = e.Item.dataitem("sz")<BR> price = e.Item.dataitem("price")<BR> 'build color display<BR> MyList = CType(e.Item.FindControl("MyList"), dropdownlist)<BR> Dim arParams(4) As SqlParameter<BR> arParams(0) = New SqlParameter("@param1", strUid)<BR> arParams(1) = New SqlParameter("@param2", size)<BR> arParams(2) = New SqlParameter("@param3", price)<BR> arParams(3) = New SqlParameter("@param4", description)<BR> arParams(4) = New SqlParameter("@param5", prod)<BR> MyList.DataSource = SqlHelper.ExecuteReader(ConfigurationSettings.AppS ettings("cnnString"), CommandType.StoredProcedure,"LS_Product_ListColor",arParams)<BR> MyList.DataBind()<BR> lblColor = CType(e.Item.FindControl("lblColor"), Label)<BR> If Mylist.items.Count < 1 Then<BR> 'throw error<BR> Else If Mylist.items.Count = 1 Then<BR> lblColor.visible="True"<BR> lblColor.Text = Mylist.items.item(0).ToString & "<INPUT TYPE=hidden runat=server id=sku" & e.Item.ItemIndex + 2 & " type=hiddden name=sku" & e.Item.ItemIndex + 2 & " value=http://aspmessageboard.com/archive/index.php/" & Mylist.items.item(0).Value.ToString & ">"<BR> MyList.visible="False"<BR> Else If Mylist.items.Count > 1 Then<BR> MyItem.Value = "none"<BR> MyItem.Text = "Select Color"<BR> MyList.Items.Insert(0,MyItem)<BR> End If<BR>End Sub<BR><BR><BR><BR><BR>.


