﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>InstantASP Community Forums / General Discussion / General Chit-Chat  / Retrieving control values from within a DataList / Latest Posts</title><generator>InstantForum.NET v4.1.4</generator><description>InstantASP Community Forums</description><link>http://community.instantasp.co.uk/</link><webMaster>sales@instantasp.co.uk</webMaster><lastBuildDate>Mon, 01 Dec 2008 18:50:18 GMT</lastBuildDate><ttl>20</ttl><item><title>Retrieving control values from within a DataList</title><link>http://community.instantasp.co.uk/Topic5704-23-1.aspx</link><description>Many thanks all for taking part in the first .NET topic, I'll try to chip in on others :)</description><pubDate>Wed, 20 Apr 2005 06:53:40 GMT</pubDate><dc:creator>Ryan Healey</dc:creator></item><item><title>Retrieving control values from within a DataList</title><link>http://community.instantasp.co.uk/Topic5704-23-1.aspx</link><description>:w00t:&lt;/P&gt;&lt;P&gt;Nice on Jimmy!&lt;/P&gt;&lt;P&gt;It is always something silly... :D</description><pubDate>Tue, 19 Apr 2005 22:47:03 GMT</pubDate><dc:creator>Cradz</dc:creator></item><item><title>Retrieving control values from within a DataList</title><link>http://community.instantasp.co.uk/Topic5704-23-1.aspx</link><description>Great glad it worked.  :)</description><pubDate>Tue, 19 Apr 2005 22:41:12 GMT</pubDate><dc:creator>Jimmy Stuart</dc:creator></item><item><title>Retrieving control values from within a DataList</title><link>http://community.instantasp.co.uk/Topic5704-23-1.aspx</link><description>Jimmy... you were right!!!!&lt;/P&gt;&lt;P&gt;I just need to set the 'text' value for the labels &amp;amp; the hyperlink control...&lt;/P&gt;&lt;P&gt;See... I told you I was doing something stupid &amp;amp; that I had been looking at this code for too long...&lt;/P&gt;&lt;P&gt;You guys rock!!!&lt;/P&gt;&lt;P&gt;Thank you, so much!!!!</description><pubDate>Tue, 19 Apr 2005 22:36:26 GMT</pubDate><dc:creator>Bare</dc:creator></item><item><title>Retrieving control values from within a DataList</title><link>http://community.instantasp.co.uk/Topic5704-23-1.aspx</link><description>On the hlinkitem_title hyperlink you are trying to set the text for it the same way you were setting the text on the labels.  asp:Hyperlink uses the same Text attribute that asp:Label does.  You seem to be trying to pull an HTML &amp;lt;a&amp;gt;text text text&amp;lt;/a&amp;gt; type deal.&lt;/P&gt;&lt;P&gt;On your first Hyperlink you are using an image, but on the second with no text, there is nothing to render I'm guessing.  This would probably be the same with the labels.</description><pubDate>Tue, 19 Apr 2005 22:35:56 GMT</pubDate><dc:creator>Jimmy Stuart</dc:creator></item><item><title>Retrieving control values from within a DataList</title><link>http://community.instantasp.co.uk/Topic5704-23-1.aspx</link><description>Actually Jimmy.. NavigationURL='...' is fine.. you can use single quotes so that you don't have to escape any double quotes inside..&lt;/P&gt;&lt;P&gt;but I think you're right about the text="" part... :)</description><pubDate>Tue, 19 Apr 2005 22:27:54 GMT</pubDate><dc:creator>Cradz</dc:creator></item><item><title>Retrieving control values from within a DataList</title><link>http://community.instantasp.co.uk/Topic5704-23-1.aspx</link><description>heh.. aye... I didn't think that would be it.. but worth a quick check.&lt;/P&gt;&lt;P&gt;Any time I use a label to hold data.. I do set it to begin with so probably why I've never come across this issue...</description><pubDate>Tue, 19 Apr 2005 22:25:36 GMT</pubDate><dc:creator>Cradz</dc:creator></item><item><title>Retrieving control values from within a DataList</title><link>http://community.instantasp.co.uk/Topic5704-23-1.aspx</link><description>I'm a newb with .net too, but from what I understand about asp:Label, you have to set the Text if you want anything to show up.  It seems to me you aren't setting the text properly and that's why its not being pulled in.  Now of course you didn't state that so I don't know for sure.  &lt;/P&gt;&lt;P&gt;You currently have:&lt;/P&gt;&lt;P&gt;&amp;lt;asp:Label id="title1" runat="server" EnableViewState="True" CssClass="txt1"&amp;gt;&amp;lt;%# DataBinder.EvalContainer.DataItem, "band_name") %&amp;gt;&amp;lt;/asp:Label&amp;gt;&lt;/P&gt;&lt;P&gt;I think you might need:&lt;/P&gt;&lt;P&gt;&amp;lt;asp:Label id="title1" runat="server" EnableViewState="True" CssClass="txt1" Text="&amp;lt;%# DataBinder.Eval(Container.DataItem, "band_name") %&amp;gt;"&amp;gt;&amp;lt;/asp:Label&amp;gt;&lt;/P&gt;&lt;P&gt;This would be similar to how you set the NavigateUrl of the Hyperlink.&lt;/P&gt;&lt;P&gt;As far as the hyperlink, you have:&lt;/P&gt;&lt;P&gt;NavigateUrl='...'&lt;/P&gt;&lt;P&gt;Should that be:&lt;/P&gt;&lt;P&gt;NavigateUrl="..."&lt;/P&gt;&lt;P&gt;Like I said, I'm a newb too, so take it all with a grain of salt.</description><pubDate>Tue, 19 Apr 2005 22:23:28 GMT</pubDate><dc:creator>Jimmy Stuart</dc:creator></item><item><title>Retrieving control values from within a DataList</title><link>http://community.instantasp.co.uk/Topic5704-23-1.aspx</link><description>I tried removing spaces and carriage returns, with no success (plus, Visual Studio just puts them right back anyway)....&lt;/P&gt;&lt;P&gt;Ya... I think i've been looking at this too long... arghhh...&lt;/P&gt;&lt;P&gt;On page load all the controls, within the datalist, bind to the correct data...  So, in testing... before retrieving the values of one of the labels...  I programmatically, changed the value of the label..  then when I retrieve the value of said label... it correctly returns the changed value...  &lt;/P&gt;&lt;P&gt;So, it seems for some reason, that even though the label is displaying and is bound to the correct data.. it truly isn't there to be retrieved.. (of course i'm saying this with the limited experience that i have)...&lt;/P&gt;&lt;P&gt;Any other ideas or suggestions would be greatly appreciated.</description><pubDate>Tue, 19 Apr 2005 22:20:47 GMT</pubDate><dc:creator>Bare</dc:creator></item><item><title>Retrieving control values from within a DataList</title><link>http://community.instantasp.co.uk/Topic5704-23-1.aspx</link><description>is price pulling from its label correctly?&lt;/P&gt;&lt;P&gt;--&lt;/P&gt;&lt;P&gt;Edit.. oh never mind. you did say the labels aren't pulling.. duh..</description><pubDate>Tue, 19 Apr 2005 21:55:02 GMT</pubDate><dc:creator>Cradz</dc:creator></item><item><title>Retrieving control values from within a DataList</title><link>http://community.instantasp.co.uk/Topic5704-23-1.aspx</link><description>Hmm... for the life of my I can't see it...&lt;/P&gt;&lt;P&gt;Try removing the spaces in the label and the link.. make em all on one line..&lt;/P&gt;&lt;P&gt;just a thought...</description><pubDate>Tue, 19 Apr 2005 21:53:56 GMT</pubDate><dc:creator>Cradz</dc:creator></item><item><title>Retrieving control values from within a DataList</title><link>http://community.instantasp.co.uk/Topic5704-23-1.aspx</link><description>Visual Studio reformats the html and makes it look really pathetic :(&lt;/P&gt;&lt;P&gt;and I'm pretty new to this... :hehe:</description><pubDate>Tue, 19 Apr 2005 21:48:50 GMT</pubDate><dc:creator>Bare</dc:creator></item><item><title>Retrieving control values from within a DataList</title><link>http://community.instantasp.co.uk/Topic5704-23-1.aspx</link><description>Here is the datalist portion of the html...&lt;/P&gt;&lt;P&gt;&amp;lt;asp:datalist id="Itemlist" runat="server" RepeatDirection="Horizontal" ShowFooter="False" RepeatColumns="3"&lt;BR&gt;       Width="100%" ShowHeader="False"&amp;gt;&lt;BR&gt;       &amp;lt;HeaderTemplate&amp;gt;&lt;BR&gt;        Recently Added Items&lt;BR&gt;       &amp;lt;/HeaderTemplate&amp;gt;&lt;BR&gt;       &amp;lt;AlternatingItemStyle CssClass="tblinvis"&amp;gt;&amp;lt;/AlternatingItemStyle&amp;gt;&lt;BR&gt;       &amp;lt;ItemStyle CssClass="tblinvis"&amp;gt;&amp;lt;/ItemStyle&amp;gt;&lt;BR&gt;       &amp;lt;ItemTemplate&amp;gt;&lt;BR&gt;        &amp;lt;P align="center"&amp;gt;&lt;BR&gt;         &amp;lt;asp:HyperLink id=image runat="server" EnableViewState="True" CssClass="btnhyper2" ImageUrl='&amp;lt;%# ConfigurationSettings.AppSettings("lfm_item_image_path")+GetThumbnail(DataBinder.Eval(Container.DataItem, "item_id")) %&amp;gt;' NavigateUrl='&amp;lt;%# "~/items/viewitem.aspx?item="&amp;amp;amp;DataBinder.Eval(Container.DataItem, "item_id") %&amp;gt;'&amp;gt;&lt;BR&gt;         &amp;lt;/asp:HyperLink&amp;gt;&amp;lt;BR&amp;gt;&lt;BR&gt;         &amp;lt;asp:Label id="title1" runat="server" EnableViewState="True" CssClass="txt1"&amp;gt;&lt;BR&gt;          &amp;lt;%# DataBinder.Eval(Container.DataItem, "band_name") %&amp;gt;&lt;BR&gt;         &amp;lt;/asp:Label&amp;gt;&amp;lt;BR&amp;gt;&lt;BR&gt;         &amp;lt;asp:HyperLink id=hlinkitem_title runat="server" EnableViewState="True" NavigateUrl='&amp;lt;%# "~/items/viewitem.aspx?item="&amp;amp;amp;DataBinder.Eval(Container.DataItem, "item_id") %&amp;gt;'&amp;gt;&lt;BR&gt;          &amp;lt;%# DataBinder.Eval(Container.DataItem, "item_title") %&amp;gt;&lt;BR&gt;         &amp;lt;/asp:HyperLink&amp;gt;&amp;lt;BR&amp;gt;&lt;BR&gt;         &amp;lt;asp:Label id="price" runat="server" EnableViewState="True" CssClass="txt2"&amp;gt;&lt;BR&gt;          &amp;lt;%# "$"+Format(DataBinder.Eval(Container.DataItem, "price"), "##,##0.00") %&amp;gt;&lt;BR&gt;         &amp;lt;/asp:Label&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&lt;BR&gt;         &amp;lt;asp:TextBox id="lblqty" runat="server" EnableViewState="True" CssClass="txtboxinput" Width="25px"&lt;BR&gt;          Columns="1"&amp;gt;1&amp;lt;/asp:TextBox&amp;gt;&amp;amp;nbsp; &amp;amp;nbsp;&lt;BR&gt;         &amp;lt;asp:DropDownList id=ddlsizes runat="server" EnableViewState="True" CssClass="dropdown" Width="100px" DataValueField="size_id" DataTextField="size_desc" DataSource='&amp;lt;%# GetSizes(DataBinder.Eval(Container.DataItem, "item_id")) %&amp;gt;' visible="&amp;lt;%# AreThereSizes %&amp;gt;" &amp;gt;&lt;BR&gt;         &amp;lt;/asp:DropDownList&amp;gt;&amp;lt;BR&amp;gt;&lt;BR&gt;         &amp;lt;asp:Button id=btnbuy runat="server" EnableViewState="True" CssClass="btn2" Width="150px" CommandName="AddToCart" Text='&amp;lt;%# CheckStock(DataBinder.Eval(Container.DataItem, "item_id")) %&amp;gt;' enabled="&amp;lt;%# IsThereStock %&amp;gt;" &amp;gt;&lt;BR&gt;         &amp;lt;/asp:Button&amp;gt;&amp;lt;BR&amp;gt;&lt;BR&gt;         &amp;lt;asp:RangeValidator id="rval_qty" runat="server" EnableViewState="False" CssClass="val" Display="Dynamic"&lt;BR&gt;          ForeColor=" " MinimumValue="1" MaximumValue="999" ControlToValidate="lblqty" ErrorMessage="RangeValidator"&amp;gt;Please enter a valid quantity&amp;lt;/asp:RangeValidator&amp;gt;&amp;lt;BR&amp;gt;&lt;BR&gt;         &amp;lt;asp:Label id="lbl_item_id" runat="server" EnableViewState="True" CssClass="txt1"&amp;gt;&lt;BR&gt;          &amp;lt;%# DataBinder.Eval(Container.DataItem, "item_id") %&amp;gt;&lt;BR&gt;         &amp;lt;/asp:Label&amp;gt;&amp;lt;BR&amp;gt;&lt;BR&gt;       &amp;lt;/ItemTemplate&amp;gt;&lt;BR&gt;       &amp;lt;HeaderStyle CssClass="thead"&amp;gt;&amp;lt;/HeaderStyle&amp;gt;&lt;BR&gt;      &amp;lt;/asp:datalist&amp;gt;</description><pubDate>Tue, 19 Apr 2005 21:44:00 GMT</pubDate><dc:creator>Bare</dc:creator></item><item><title>Retrieving control values from within a DataList</title><link>http://community.instantasp.co.uk/Topic5704-23-1.aspx</link><description>Hey Bare,&lt;/P&gt;&lt;P&gt;Can you show us the HTML code?</description><pubDate>Tue, 19 Apr 2005 21:21:05 GMT</pubDate><dc:creator>Cradz</dc:creator></item><item><title>Retrieving control values from within a DataList</title><link>http://community.instantasp.co.uk/Topic5704-23-1.aspx</link><description>Hi everyone,&lt;/P&gt;&lt;P&gt;I've been programming for many years, but have just started teaching myself .NET within the last year.. and I have an issue, in which I could use some of your expert advice ;)&lt;/P&gt;&lt;P&gt;(This is developed in vb.net)&lt;/P&gt;&lt;P&gt;I'm populating a Datalist on page load (if not ispostback).  There are are a series of controls, within the datalist (labels, a textbox, a hyperlink, a button &amp;amp; a dropdownlist).&lt;/P&gt;&lt;P&gt;When the button is clicked (CommandName = AddToCart), I'm retrieving the values of these controls and populating some session variables.  It works great for the textbox &amp;amp; dropdownlist, but for some reason I'm unable to retrieve the values from the labels &amp;amp; hyperlink.&lt;/P&gt;&lt;P&gt;The code compiles properly and executes properly, but the values from the labels &amp;amp; hyperlink are blank.&lt;/P&gt;&lt;P&gt;At this point, all of the controls, including the datalist, have enableviewstate = true&lt;/P&gt;&lt;P&gt;Here is the code, that I have within the Itemlist_ItemCommand sub procedure:&lt;/P&gt;&lt;P&gt;**************&lt;BR&gt;If e.CommandName = "AddToCart" Then&lt;/P&gt;&lt;P&gt;   Session("item_id") = CType(e.Item.FindControl("lbl_item_id"), Label).Text&lt;BR&gt;   Session("item_desc") = CType(e.Item.FindControl("hlinkitem_title"), HyperLink).Text&lt;BR&gt;   Session("price") = CType(e.Item.FindControl("price"), Label).Text&lt;BR&gt;   Session("quantity") = CType(e.Item.FindControl("lblqty"), TextBox).Text&lt;/P&gt;&lt;P&gt;   If CType(e.Item.FindControl("ddlsizes"), DropDownList).Enabled = True Then&lt;BR&gt;      Session("size_id") = CType(e.Item.FindControl("ddlsizes"), DropDownList).SelectedItem.Value&lt;BR&gt;      Session("size") = CType(e.Item.FindControl("ddlsizes"), DropDownList).SelectedItem.Text&lt;BR&gt;   Else&lt;BR&gt;      Session("size_id") = "0"&lt;BR&gt;      Session("size") = "No Size"&lt;BR&gt;   End If&lt;/P&gt;&lt;P&gt;End If&lt;BR&gt;***************&lt;/P&gt;&lt;P&gt;Here is the trace, of the itemlist:  (The problem controls seem to be the 'databoundliteralcontrols'...  This is where i could use some learning &amp;amp; your help)...&lt;/P&gt;&lt;P&gt;        Itemlist System.Web.UI.WebControls.DataList 5637 76 &lt;BR&gt;            Itemlist:_ctl0 System.Web.UI.WebControls.DataListItem 0 0 &lt;BR&gt;                Itemlist:_ctl0:_ctl0 System.Web.UI.LiteralControl 0 0 &lt;BR&gt;            Itemlist:_ctl1 System.Web.UI.WebControls.DataListItem 1288 0 &lt;BR&gt;                Itemlist:_ctl1:_ctl0 System.Web.UI.LiteralControl 39 0 &lt;BR&gt;                Itemlist:_ctl1:image System.Web.UI.WebControls.HyperLink 133 116 &lt;BR&gt;                Itemlist:_ctl1:_ctl1 System.Web.UI.LiteralControl 15 0 &lt;BR&gt;                Itemlist:_ctl1:title1 System.Web.UI.WebControls.Label 58 0 &lt;BR&gt;                    Itemlist:_ctl1:_ctl2 System.Web.UI.DataBoundLiteralControl 5 12 &lt;BR&gt;                Itemlist:_ctl1:_ctl3 System.Web.UI.LiteralControl 15 0 &lt;BR&gt;                Itemlist:_ctl1:hlinkitem_title System.Web.UI.WebControls.HyperLink 106 76 &lt;BR&gt;                    Itemlist:_ctl1:_ctl4 System.Web.UI.DataBoundLiteralControl 35 52 &lt;BR&gt;                Itemlist:_ctl1:_ctl5 System.Web.UI.LiteralControl 15 0 &lt;BR&gt;                Itemlist:_ctl1:price System.Web.UI.WebControls.Label 58 0 &lt;BR&gt;                    Itemlist:_ctl1:_ctl6 System.Web.UI.DataBoundLiteralControl 6 16 &lt;BR&gt;                Itemlist:_ctl1:_ctl7 System.Web.UI.LiteralControl 23 0 &lt;BR&gt;                Itemlist:_ctl1:lblqty System.Web.UI.WebControls.TextBox 136 0 &lt;BR&gt;                Itemlist:_ctl1:_ctl8 System.Web.UI.LiteralControl 24 0 &lt;BR&gt;                Itemlist:_ctl1:ddlsizes System.Web.UI.WebControls.DropDownList 0 124 &lt;BR&gt;                Itemlist:_ctl1:_ctl9 System.Web.UI.LiteralControl 15 0 &lt;BR&gt;                Itemlist:_ctl1:btnbuy System.Web.UI.WebControls.Button 260 68 &lt;BR&gt;                Itemlist:_ctl1:_ctl10 System.Web.UI.LiteralControl 15 0 &lt;BR&gt;                Itemlist:_ctl1:rval_qty System.Web.UI.WebControls.RangeValidator 289 0 &lt;BR&gt;                Itemlist:_ctl1:_ctl11 System.Web.UI.LiteralControl 15 0 &lt;BR&gt;                Itemlist:_ctl1:lbl_item_id System.Web.UI.WebControls.Label 59 0 &lt;BR&gt;                    Itemlist:_ctl1:_ctl12 System.Web.UI.DataBoundLiteralControl 1 8 &lt;BR&gt;                Itemlist:_ctl1:_ctl13 System.Web.UI.LiteralControl 13 0 &lt;BR&gt;*****************&lt;/P&gt;&lt;P&gt;Here are the session state traces, that I'm failing to retrieve values. (the dropdownlist and textbox return values correctly, but not the labels &amp;amp; hyperlink)&lt;/P&gt;&lt;P&gt;item_id System.String   &lt;BR&gt;item_desc System.String   &lt;BR&gt;price System.String   &lt;/P&gt;&lt;P&gt;*****************&lt;/P&gt;&lt;P&gt;Along with CType, I have also attempted Directcast, with no luck..&lt;/P&gt;&lt;P&gt;Can anyone offer some much needed advice?&lt;/P&gt;&lt;P&gt;I'm sure I'm doing something stupid, but please be gentle :D</description><pubDate>Tue, 19 Apr 2005 20:56:57 GMT</pubDate><dc:creator>Bare</dc:creator></item></channel></rss>