473,811 Members | 1,788 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Conditional (if statement) in a datagrid

Hi,

I have a datagrid and based on a condition I like to display either a
asp:textbox or asp:label. How would I do that? I have the following

<asp:TemplateCo lumn HeaderText="Qty ">
<ItemTemplate >
<% if (DataBinder.Eva l(Container.Dat aItem, "DynamicAttribu te") = "No")
{%>

<asp:textbox id="tbxQtyNew" BackColor='<%#
SetTextBoxColor (DataBinder.Eva l(Container.Dat aItem,
"DynamicAttribu te")) %>' runat="server" text='1' />
<% } else { %>
<asp:Label id="lblQtyDisp " Text="1" runat="server"/>
<% } %> </ItemTemplate>
</asp:TemplateCol umn>

Which fails. Any idea?

Thanks
Maz.

Mar 2 '06 #1
1 3365
It might be easier to do it from code-behind. Alot cleaner and more
efficient.
Use OnItemDataBound event and put all of logic in ItemDataBound
handler.

Leave both textbox and label controls on .aspx page with their Visible
property set to False. Then from the code-behind, do something like:

public void HandleItemDataB ound(object sender, DataGridItemEve ntArgs e)

{
if (e.Item.ItemTyp e == ListItemType.It em ||
e.Item.ItemType == ListItemType.Al ternatingItem)
{
SomeClass oItem = (SomeClass) e.Item.DataItem ;
if (oItem.SomeProp erty == "SomeValue" ) {
// show label
} else {
// show textbox
}
oItem = null;
}
}

Hope it helps!

Amie

Mar 2 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
9340
by: Shaldaman | last post by:
I have an Access form called "Login". "Command10" is a button on the form and "Text5" is a text field on it. When a user enters a value in the Text5 text field and clicks the button Command10, I want my function to check if the value in Text5 matches any value of InstructorID in the Instructor table. If yes, I would like the control to switch to another form called "Existing Instructor" else I'd like to generate a message to the user that...
8
1654
by: arganx | last post by:
The conditional statement "if(j.... always executes regardless of what you enter. BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam) { char buffer=""; GetWindowText(hwnd,buffer,256); if(!strcmp(buffer,"")) { return TRUE;
5
2540
by: Gary Wessle | last post by:
Hi if I have a method like this bool myClass::myMothod(myType& mt, herType ht) throw ( SomeExp ); how can I use it in a conditional statement if ( try {
43
7591
by: dev_cool | last post by:
Hello friends, I'm a beginner in C programming. One of my friends asked me to write a program in C.The purpose of the program is print 1 to n without any conditional statement, loop or jump. How is it possible? Please help me. Thanks in advance.
5
2428
by: bamn68 | last post by:
how do i use conditional statement in sql? im using access 2003 as frontend and backend. What would be the SQL statement for the situation below? I would like to count the number of records in a table (ex. ENROLL) where there is only 1 instance of any value in a field (ex. STUDENT_NO) plus another condition where a given value (ex. 1) should exist in another field (ex. SECTION). Example Table name: ENROLL STUDENT_NO SECTION FEE
0
1404
by: cljordan | last post by:
I am trying to create a database that list materials and their quantities, and highlights quantities that come up outside a certain percentage range against the average. I have tried the following conditional formatting: Condition 1: >Avg()*1.5; Condition 2: <Avg()*0.5 However, there are a lot of different materials that differ in quantity, and what the report is doing is averaging all of the quantities instead of just the ones under...
0
10648
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10402
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10135
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9205
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7670
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6890
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5554
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3867
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.