DataList - Changing the Value based on a DB value returned

Hi guys.

What i want to do is display a different text value with the value returned from the db based on what is returned from the database for that field.
I would like to display that into a label within a Datalist

I thought i could do something along these lines.

<asp:Label id ="lblStock"> <% #Sub( DataBinder.Eval (Container.DataItem, "IntegerField"))%> </asp:Label>

Create the Sub and based on the Integer Field with some conditional operations
Then write the lblStock.Text propery + the IntegerField value.

Can something like that be done or will i have to write this within the ItemDataBound function, find my label control and go from there.


9/24/2005 4:23:40 AM 72751 articles. 3 followers. Follow

5 Replies

Similar Articles

[PageSpeed] 3

It can be done exactly as you suggested, even your syntax is correct.

9/24/2005 4:43:57 AM
Hi, feel free to read this reference . Hope this helps...
Alvin Chooi
Microsoft ASP.NET™ Enthusiast v1.1 / v2.0, Malaysia
Blog :
9/24/2005 6:28:45 AM
Thanks for the help guys. 

Managed to get it to work finally.

9/24/2005 8:33:39 PM
I have in someway a simular issue a xTripx posted (I think). I use a form with several dropdownboxes in which the result is stored as an integer value in the database. An example:

<asp:DropDownList id="ddlFoods" runat="server"
   <asp:ListItem value="0">No value selected</asp:ListItem>
   <asp:ListItem value="1">Apple</asp:ListItem>
   <asp:ListItem value="2">Tomato</asp:ListItem>
   <asp:ListItem value="3">Banana</asp:ListItem>

So, if Tomato is selected 2 is stored in the database. Now, when I display this data in a DataGrid, the DataGrid will show values like 1, 2, 3,... and not Apple, Tomato, Banana,... How can I best handle this?


Best Regards!
9/25/2005 5:51:04 PM
Hello again Wim!

You could join to the talb containing the Fruit descriptions in your SQL statement and display the translated values that way, or as this thread mentions, use a helper function to lookup the description based on the code of 2.  Here is a simple example, though it doesn't use the database to translate values:

9/25/2005 9:54:03 PM

Similar Artilces:

new to .net, need help setting db values from checkbox's then retrieving value to a label control
Hi, Being new to i know this possible i just can't quite get it right!  I need a page with 5 checkbox's that when submitted sets the bit values in DB fields to checked. Then i need another page that retrieves the records of the checkboxes, but instead of having the db pre-set checkboxes on the second page i want it to turn on label web controls depending on if the check box is set.. I hope that makes sense?!! Can anyone point me in the right direction or to a suitable tutorial? Thanks in advance Ben Excellent article here.

Control.Value and Control.SelectedItem.Value
Can someone explain to me the difference between say, Dropdownlist.SelectedItem.Value and Dropdownlist.SelectedValue?? Just curious, Thanks!Tim These are going to return the same thing. dropdownlist.selectedvalue is a shortcut to get the currently selected value in the dropdown. If that is all you want then you can just use that. If you want to access the currently selected item you can use dropdownlist.selecteditem and that return the item and you can then access any of the item's properties, including in this case the value property. If this post answered your question please r...

Default selecting listbox values based on DB values...
I have the following code in .aspx file:<asp:listbox selectionmode="Multiple" rows="6" cssclass="FormElement" datasourceid="Unions" id="ctlUnions" tabindex="25" runat="server" datatextfield="short_name" datavaluefield="union_id"></asp:listbox><asp:SqlDataSource id="Unions" datasourcemode="DataSet" enableviewstate="true"            enablecaching="true" cacheduration="Infinite" cacheexpirationpolicy="Absolute"            ConnectionString='<%$ ConnectionStrings:strDataSource %&g...

Set TextBox text value to value from DataList Control
I'm sure this is a totally sad question to ask, but... I am using a DataList View to display data. I have a separate form within a LoginView that I would like to use to update a few main fields. I want to set the Text property of the TextBox in my custom edit form to the value of the corresponding field in the DataList. Is this possible? I think i get your question --> you want the text from a  textbox from the datalist to be input into a textbox within your form? try:TextBox tb = DataList1.FindControl("TextBoxIDToFind"); TextBoxOnForm.Text = tb.Text;David Ki...

If Not value or value then....
Hi all,I want to write a simple IF Not then statement in 2.0 and I would like some help please.  If Not ntuser = "DOMAIN\ntuser" Or ntuser = "DOMAIN\ntuser2" Then Panel1.Visible = False End If Doesnt work, can you tell me where i'm going wrong please?many thanks.  The first place you're going wrong is in telling us it "doesn't work" without providing any details. JeffPlease: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue. Use Not as stated below. It ...

How to get return value or output value from stored procedure with sqldatasource control?
I created a user registration web page with sqldatasource, some textbox controls or submit button web control, I applied below stored procedure in insert command of sqldatasource control, but how can I get return value from stored procedure after clicking submit button, I want to judge whether data has been saved into database by return value, then give user a message. Who can tell me? thanks much. ALTER PROCEDURE UserInsert ( @Email nvarchar(50), @Password nvarchar(50), @FullName nvarchar(50), @Phone nvarchar(50), @Mobile nvarchar(50), @Address nvarchar(100), ...

Set value on a Container page (aspx) based on the value of a user control (ascx)
How can i change a value on the aspx page based on the value in a user control on that page. I am using codebehind on both files. Thank you. the usercontrol should expose a public property that the container can read a value from.Mike Banavige~~~~~~~~~~~~Need a site code sample in a different language? Try converting it with: Thank you. That is not what I am trying to do. How do I change a value on the Container page based on a value on the usercontrol. For example, I have a several link buttons on the Container page. Lets say i select the first l...

Correct format for setting up a control to be visible by comparing value of a DB field to a specific value.
I only want the control to display if the value of  DocNumber starts with 123, otherwise it should not display. DocNumber is a Text field Length 15 in an MS Access DB.  Is my use of like valid in this IIf statement?  I have search all over and could not find out whether or not like is a valid condition to use. Here is what I have and when I run the app, the control is always visible. Visible='<%# IIf((Eval("DocNumber")like "123"), "True", "False") %>' You can't use SQL syntax in regular code. Instead, you need to see if those three numbers appear, in that order, at...

Net::LDAP::Control returns 'ASN' value?
Hello, I've got a question about the behavior of Net::LDAP::Control and it's child classes. =20 Should a call to $control->value() return an ASN value? I instantiated a few controls to see their behavior and they are all the same. They return an ASN value. I guess I expected the original, untainted, value to be returned. (The value of Net::LDAP::Control->value() is untouched but I suspect that is because it is a simplified stub for subclasses.) Thanks, -David Faltermier #--------------------------------------- # Testing Net::LDAP:...

Pass 1 control value to another control value
I have this form, is the detailsview, and in edit mode, I have a link that you click to open up a small dhtml window (not a new window but more like a layer so everything is on the same page).  When I select an item from the dhtml window, it puts the value into a textbox.  I then have a button I click and I want to pass that value from that textbox to the textbox in the detailsview.  When I click the button, the value is not passed. Here is the code I use for getting the value from the dhtml window and assigning it to the detailsview textbox: If e.CommandName = "pi...

How to Format Data in a REPEATER Control based on a returned value in the REPEATER?
 I need help with how to control the display of the label using the REPEATER Control. If the EVENTNAMEBOLD text returns "True" then I need the EVENTNAME label to be bold, other wise it is not. Is it possible using the REPEATER control using code behind or inline code? If someone could point me in the right direction I would really appreciate it. I don't want to write my own repeater using a LOOP unless that is the only way. The Code below works to produce Sets of Data Formatted all the same. Thanks in advance for your Help! <asp:Repeater ID="Repeater1" r...

when loading a previously created record on to form, some controls are missing values(controls are depended on values selected in other controls)
Hello - I have created a page for Editing records.  this page will open up a chosen record and allow user to edit the data.On the form, I have 3 drop down lists.   The second dropdown list should fill values depending on value chosen in first dropdown list.  The third dropdown list should show/fill values depending on value chosen in second dropdown list.So taking this into count, i have several records with various data.  When I open-up/load a record in Edit form, only the first dropdown list has a value selected that was the pre-existing va...

Returning value from composite control to more than one other controls
This is not really a problem but I was curious if there was a better way to do this. I have a Composite Control that will return its value to a server control or something when it is done. I expect that it will fill a text box or a label but I wouldn’t mind if it could fill a button or any number of things that have a simple place to store text. Is there a better way than going through all of the option by hand?   Here is an example of my code.   public class DateTimeThing : CompositeControl    {        protected DateTime dateti...

Copy values based on checkbox value
I saw this in another post but can't seem to get it to work.  I tried to set a breakpoint in VS 2008 at function copyAddress() but it does not appear to be getting hit when I check my checkbox.In my .aspx I have the following Javascript:function copyAddress(){ var chkSameAddress = document.getElementById('<%= chkbxDeliveryAddrSame.ClientID %>'); var txtStreet = document.getElementById('<%= txtStreet.ClientID %>'); var txtDeliveryStreet = document.getElementById(' <%= txtDeliveryStreet.ClientID %>'); var txtZip = document.getEleme...

How to return a value or gain the value in for to loop?
Hi...I am a new bie in face a problem to return a value in for to loop, below is my code:If cb_Payroll.SelectedValue <> "" Then            For i As Integer = 0 To Me.cb_Payroll.Items.Count - 1                If Me.cb_Payroll.Items(i).Selected = True Then                    Dim var_Payroll As Integer       &nb...

Web resources about - DataList - Changing the Value based on a DB value returned -

Email Domain Datalist Helper
What if someone signs up for your web app and they type in their email address as They don't notice, they never get their ...

South-west Marine Reserves Network - Resources
[toc on_off::hide=0 on_off::automatic=0 on_off::min_limit=5 box::title=Contents box::minlevel=2 box::maxlevel=2 box::hide_show=1 box::collapsed=1 ...

工作正在进行中:实例解决方案 返回 表的图例 & 说明: “不支持" - 意味着如果提供有建设性意义的变通方案仍不能被浏览器支持。 “部分支持” - 意味着建设性意义的变通方案在浏览器中提供一些无障碍支持。 “没实现” - 意味着新特性在浏览器中仍然没有实现。 “支持” - means ...

... 鏂扮櫧鍙戦瓟濂充紶 鏄庢湞澶╁惎鍥涘勾锛屽箍鍏冨湴鍖鸿繛骞撮ゥ鑽?.. 娓╁窞涓€瀹朵汉 銆婃俯宸炰竴瀹朵汉銆嬩互涓€鎴锋櫘閫氫汉瀹剁殑... 闃垮浣块亾浼?/a> 銆婇樋濞樹娇閬撲紶銆嬩互鏈濋矞鏃朵唬涓鸿儗鏅?.. 鐑棬瑙嗛 姝e湪鍔犺浇...璇风◢绛墌 ${++dataList_index} ...

Adactio: Journal
The thoughts and ramblings of Jeremy Keith, a web developer living in Brighton in southern England.

datalist experiment
demo implementation of datalist element

Issues for pfeldman - Code Review
Keyboard Shortcuts File u : up to issue m : publish + mail comments M : edit review message j / k : jump to file after / before current file ...

Google’s new Chrome Beta 24 is 26% faster than last year’s browser
... the Octane Javascript benchmark. For developers, there are tons of new features in Chrome Beta 24 including new un-prefixed APIs, MathML, datalist ...

Accessible Mozilla: Firefox 24
Alex's blog Wednesday, July 10, 2013 Here's a list of Firefox 24 (currently Aurora ) improvements for assistive technology. ARIA We supported ...

Google Chrome 24 Released, Claims 26% Speed Improvement
Google today released a new version of its browser. On the Octane benchmark, this version is claimed to have 26% speed improvement over the last ...

Resources last updated: 12/14/2015 12:51:02 AM