473,396 Members | 1,693 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,396 software developers and data experts.

How to apply conditions to databound objects

147 100+
I use a repeater on my website.

My code for this example is

Expand|Select|Wrap|Line Numbers
  1. <ItemTemplate>
  2. Item: <%#DataBinder.Eval(Container.DataItem, "Col")%><br>
  3. </ItemTemplate>
Now, depending on the result of the dataitem will depend on what I want to display. For example, The databitem may show a true or false value, and depending on which one I want to show a different result on my page. So instead of it display true, it display a string. EG, if true, the text 'in stock' would display.

At the moment, I am using a method to call a function (please correct my terminology - or let me know my terminology is right!).
html:
Expand|Select|Wrap|Line Numbers
  1. <ItemTemplate>
  2. Item: <%#CB(DataBinder.Eval(Container.DataItem, "Col"))%><br>
  3. </ItemTemplate>
code behind:
Expand|Select|Wrap|Line Numbers
  1. public string CB(object o)
  2. {
  3. //perform something
  4. return string.format("");
  5. }
Is this the best way as it appears to be an ugly fix in my opinion. Especially as I have several items on my page which will have to use this (ususally just checking if there is a value in the dataitem or if it is empty/null)

Thanks

Dave
Oct 20 '10 #1

✓ answered by Frinavale

I used to do the same thing but changed my approach to use an If function or an IIF function instead.

You're using C#...so I'm not sure if you have the If-function at your disposal and I'm not sure if the same peculiar problems exist with the IIF in C# as exist in VB.NET(where the true and false parts of the method are always executed...which can be a problem if the if-statement was checking if something was null)

If your logic is complex then it might be a good idea to keep doing what you are doing...

But if you are trying to do something simple like printing "in stock" instead of "true" then the If-function or IIF-Function will do nicely.

-Frinny

2 1286
Frinavale
9,735 Expert Mod 8TB
I used to do the same thing but changed my approach to use an If function or an IIF function instead.

You're using C#...so I'm not sure if you have the If-function at your disposal and I'm not sure if the same peculiar problems exist with the IIF in C# as exist in VB.NET(where the true and false parts of the method are always executed...which can be a problem if the if-statement was checking if something was null)

If your logic is complex then it might be a good idea to keep doing what you are doing...

But if you are trying to do something simple like printing "in stock" instead of "true" then the If-function or IIF-Function will do nicely.

-Frinny
Oct 20 '10 #2
DaveRook
147 100+
Hi Frinny

Thank you (again) for your help. As disapointing as it is to have to continue this way as sometimes the logic is more complicated than simple if else statements, it is quite re-assuring to know this is a 'normal' programming dilema and there is not a simple solution. At least I'm on the right path and using the language effectively!

I am using T-SQL and C# so I guess it's case statements for me!!

Thank you again for your feedback

Dave
Oct 21 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: David B | last post by:
Bare with me this is my first post. Objective: To dynamically create repeaters in a WebForm based on sets of data. Problem: When I attempt to create any Repeater from C# I get a big fat white...
3
by: DonRex | last post by:
Hello all! I couldn't find a web application-newsgroup for ASP.NET, so I'm sorry if this is the wrong forum! Synopsis: In my webform I have 3 nested repeaters: rpWeeks ----- rpTime
0
by: Paul | last post by:
I want to be able to nest a repeater in a datagrid or datalist. I'm not unduly bothered about a master/child relationship as such as there'll at this stage only ever be one record on the page, but...
0
by: Machi | last post by:
let say in parent-child scenerio (Product: Product Category - one product category may has many products), i am using nested repeaters where parent repeater will be used to display info and child...
0
by: kettch | last post by:
Is it possible to have nested repeaters three layers deep I have gotten it to work with only two, and when I tried to get the third layer to work COD <asp:repeater id="rep"...
1
by: garethdjames | last post by:
Please can some on offer some practicle advice, I am designing a page that displays details about a product, the page will be navigated from a datagrid (this bit no problem), The details page...
1
by: Roy | last post by:
No errors here, I'm just looking for ways to make my code more efficient. As the subject line suggests, I have a LOT of repeaters on a certain page. They are visible or hidden depending on user...
1
PrinsonG
by: PrinsonG | last post by:
My Query is How do I export to excel/csv using Nested Repeaters. My project is web-based and i am using C#.Net. In this i use three repeaters. one displays ID, Name of the user. second...
1
by: andrew.douglas11 | last post by:
Hello all, Is it possible to share controls inside a child repeater? Here's the situation: I have a web page that needs to display data grouped by A, and alternatively by B (only one grouping...
3
by: Leon Mayne | last post by:
If I have a datatable which looks like this: Record Id, Group Id, Name 1, 1, Test 1 2, 1, Test 2 3, 2, Test 3 4, 3, Test 4 Is it possible to use nested repeaters to group the information by...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.