two ways to find a label control in a gridview and set its text property.
Which is the perfered way I perfer the first one, but i'm new to cs.
protected void GridView1_RowCr eated(object sender, GridViewRowEven tArgs e)
{
if (e.Row.RowType == DataControlRowT ype.DataRow)
{
// type 1 is more "C" Like
if (((GridViewRow) e.Row).FindCont rol("lbl_One1") != null)
((Label)((GridV iewRow)e.Row).F indControl("lbl _One1")).Text =
"YES!";
// type 2 more VB like
if (((GridViewRow) e.Row).FindCont rol("lbl_One1") != null)
{
Label lbl =
(Label)((GridVi ewRow)e.Row).Fi ndControl("lbl_ Two2");
lbl.Text = "AND Yes!";
}
}
}
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)
kes 21 1294
Hi,
Maybe I got lost in so many () , but what is the difference between both
variants?
They look the same to me, just that in the 2dn version you use a temp
variable.
"WebBuilder 451" <We***********@ discussions.mic rosoft.comwrote in message
news:E4******** *************** ***********@mic rosoft.com...
two ways to find a label control in a gridview and set its text property.
Which is the perfered way I perfer the first one, but i'm new to cs.
protected void GridView1_RowCr eated(object sender, GridViewRowEven tArgs e)
{
if (e.Row.RowType == DataControlRowT ype.DataRow)
{
// type 1 is more "C" Like
if (((GridViewRow) e.Row).FindCont rol("lbl_One1") != null)
((Label)((GridV iewRow)e.Row).F indControl("lbl _One1")).Text =
"YES!";
// type 2 more VB like
if (((GridViewRow) e.Row).FindCont rol("lbl_One1") != null)
{
Label lbl =
(Label)((GridVi ewRow)e.Row).Fi ndControl("lbl_ Two2");
lbl.Text = "AND Yes!";
}
}
}
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)
kes
that is the idea, they do the samething, but are they samething? Are they
both way too complicated?, how would you do it?
Also, is one way safer or better?
given that i created a temp variable in the second does this use more
memory, albeit verry little more, than the first because it's creating a
temp; Or is the temp created anyway by using the cast because CLR just does
it that way?
It's not C++ so i'm trying to learn what's best for this langage.
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)
kes
"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,
Maybe I got lost in so many () , but what is the difference between both
variants?
They look the same to me, just that in the 2dn version you use a temp
variable.
"WebBuilder 451" <We***********@ discussions.mic rosoft.comwrote in message
news:E4******** *************** ***********@mic rosoft.com...
two ways to find a label control in a gridview and set its text property.
Which is the perfered way I perfer the first one, but i'm new to cs.
protected void GridView1_RowCr eated(object sender, GridViewRowEven tArgs e)
{
if (e.Row.RowType == DataControlRowT ype.DataRow)
{
// type 1 is more "C" Like
if (((GridViewRow) e.Row).FindCont rol("lbl_One1") != null)
((Label)((GridV iewRow)e.Row).F indControl("lbl _One1")).Text =
"YES!";
// type 2 more VB like
if (((GridViewRow) e.Row).FindCont rol("lbl_One1") != null)
{
Label lbl =
(Label)((GridVi ewRow)e.Row).Fi ndControl("lbl_ Two2");
lbl.Text = "AND Yes!";
}
}
}
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)
kes
"WebBuilder 451" <We***********@ discussions.mic rosoft.comwrote in message
news:B0******** *************** ***********@mic rosoft.com...
that is the idea, they do the samething, but are they samething? Are they
both way too complicated?, how would you do it?
Also, is one way safer or better?
given that i created a temp variable in the second does this use more
memory, albeit verry little more, than the first because it's creating a
temp; Or is the temp created anyway by using the cast because CLR just
does
it that way?
I think it comes down to personal preference, and I don't believe that
either method is appreciably more efficient than the other...
I have a personal preference for the first option...
I'm sure that other people would say that the second option is more
readable...
--
Mark Rae
ASP.NET MVP http://www.markrae.net
Appreciate your response (from both of you). Upon a little work i discovered
that i can do the same thing in vb.net but this style is frowned upon for
it's wordiness
consider: C# (please ignore the lack of error checking)
((TextBox)((ASP .master_mp2_mas ter)Master).Fin dControl("TextB ox1")).Text =
"YES";
vs VB
DirectCast(Dire ctCast(Master,
ASP.master_mp2_ master).FindCon trol("TextBox1" ), TextBox).Text = "YES"
Most would break this up into steps, where as i would not unless i had to.
My concern is that my statements are getting too wordy, they are not too for
me because i did C and C++ 15 years ago, but this is C# not C++ and i want to
learn good coding practices.
Thanks!!! (I owe you both a favor)
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)
kes
"Mark Rae [MVP]" wrote:
"WebBuilder 451" <We***********@ discussions.mic rosoft.comwrote in message
news:B0******** *************** ***********@mic rosoft.com...
that is the idea, they do the samething, but are they samething? Are they
both way too complicated?, how would you do it?
Also, is one way safer or better?
given that i created a temp variable in the second does this use more
memory, albeit verry little more, than the first because it's creating a
temp; Or is the temp created anyway by using the cast because CLR just
does
it that way?
I think it comes down to personal preference, and I don't believe that
either method is appreciably more efficient than the other...
I have a personal preference for the first option...
I'm sure that other people would say that the second option is more
readable...
--
Mark Rae
ASP.NET MVP http://www.markrae.net
Hi,
No offense, but not only is that stuff unreadable, but it is also very
inefficient. How about :
// The label to show <insert comment>
Label label = (e.Row as GridViewRow).Fi ndControl (LABEL_BLOB) as Label;
// The label was not found, we are therefore showing a non-BLOB page
if (label != null)
{
label.Text = "Yes";
}
I would also see if the first line could be improved by looking at the
details of how it is setup etc, but for now, this would be a good start.
Hilton
"WebBuilder 451" <We***********@ discussions.mic rosoft.comwrote in message
news:E4******** *************** ***********@mic rosoft.com...
two ways to find a label control in a gridview and set its text property.
Which is the perfered way I perfer the first one, but i'm new to cs.
protected void GridView1_RowCr eated(object sender, GridViewRowEven tArgs e)
{
if (e.Row.RowType == DataControlRowT ype.DataRow)
{
// type 1 is more "C" Like
if (((GridViewRow) e.Row).FindCont rol("lbl_One1") != null)
((Label)((GridV iewRow)e.Row).F indControl("lbl _One1")).Text =
"YES!";
// type 2 more VB like
if (((GridViewRow) e.Row).FindCont rol("lbl_One1") != null)
{
Label lbl =
(Label)((GridVi ewRow)e.Row).Fi ndControl("lbl_ Two2");
lbl.Text = "AND Yes!";
}
}
}
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)
kes
non-taken at all. This is what i wanted!!
Thank you!
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)
kes
"Hilton" wrote:
Hi,
No offense, but not only is that stuff unreadable, but it is also very
inefficient. How about:
// The label to show <insert comment>
Label label = (e.Row as GridViewRow).Fi ndControl (LABEL_BLOB) as Label;
// The label was not found, we are therefore showing a non-BLOB page
if (label != null)
{
label.Text = "Yes";
}
I would also see if the first line could be improved by looking at the
details of how it is setup etc, but for now, this would be a good start.
Hilton
"WebBuilder 451" <We***********@ discussions.mic rosoft.comwrote in message
news:E4******** *************** ***********@mic rosoft.com...
two ways to find a label control in a gridview and set its text property.
Which is the perfered way I perfer the first one, but i'm new to cs.
protected void GridView1_RowCr eated(object sender, GridViewRowEven tArgs e)
{
if (e.Row.RowType == DataControlRowT ype.DataRow)
{
// type 1 is more "C" Like
if (((GridViewRow) e.Row).FindCont rol("lbl_One1") != null)
((Label)((GridV iewRow)e.Row).F indControl("lbl _One1")).Text =
"YES!";
// type 2 more VB like
if (((GridViewRow) e.Row).FindCont rol("lbl_One1") != null)
{
Label lbl =
(Label)((GridVi ewRow)e.Row).Fi ndControl("lbl_ Two2");
lbl.Text = "AND Yes!";
}
}
}
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)
kes
"Hilton" <no****@nospam. comwrote in message
news:89******** *********@newss vr25.news.prodi gy.net...
it is also very inefficient.
How so...?
--
Mark Rae
ASP.NET MVP http://www.markrae.net
followup: How is it inefficient?
if i read it correctly my way is way less readable, no question, but it's
not creating an object for compairson or assignment. I'm not saying you're
wrong at all, just would like it explained.
Your answer was very appreciated!
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)
kes
"Hilton" wrote:
Hi,
No offense, but not only is that stuff unreadable, but it is also very
inefficient. How about:
// The label to show <insert comment>
Label label = (e.Row as GridViewRow).Fi ndControl (LABEL_BLOB) as Label;
// The label was not found, we are therefore showing a non-BLOB page
if (label != null)
{
label.Text = "Yes";
}
I would also see if the first line could be improved by looking at the
details of how it is setup etc, but for now, this would be a good start.
Hilton
"WebBuilder 451" <We***********@ discussions.mic rosoft.comwrote in message
news:E4******** *************** ***********@mic rosoft.com...
two ways to find a label control in a gridview and set its text property.
Which is the perfered way I perfer the first one, but i'm new to cs.
protected void GridView1_RowCr eated(object sender, GridViewRowEven tArgs e)
{
if (e.Row.RowType == DataControlRowT ype.DataRow)
{
// type 1 is more "C" Like
if (((GridViewRow) e.Row).FindCont rol("lbl_One1") != null)
((Label)((GridV iewRow)e.Row).F indControl("lbl _One1")).Text =
"YES!";
// type 2 more VB like
if (((GridViewRow) e.Row).FindCont rol("lbl_One1") != null)
{
Label lbl =
(Label)((GridVi ewRow)e.Row).Fi ndControl("lbl_ Two2");
lbl.Text = "AND Yes!";
}
}
}
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)
kes
1. "Y as X" is cheaper than "(X) Y"
2. FindControl is (sometimes) called twice instead of once. That's
significant.
Hilton
"Mark Rae [MVP]" <ma**@markNOSPA Mrae.netwrote in message
news:u8******** ******@TK2MSFTN GP06.phx.gbl...
"Hilton" <no****@nospam. comwrote in message
news:89******** *********@newss vr25.news.prodi gy.net...
>it is also very inefficient.
How so...?
--
Mark Rae
ASP.NET MVP http://www.markrae.net This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Tony Marston |
last post by:
If the use of the browser's BACK button is interfering with the operation of
your web application then take a look at this article entitle "Back Button
Blues"
http://www.tonymarston.co.uk/php-mysql/backbuttonblues.html
--
Tony Marston
http://www.tonymarston.net
|
by: DJ Majestik |
last post by:
OK, I am devising a php page that will handle a form submission, and
wanted to know if anyone has already setup such an idea, or if you had
links to point to good tutorials on this.
Basically I have a form (which I use smarty templating to display, and
smartyvalidator to validate).
The php page basically is driven by the action variable (add,
add_confirm, edit, edit_confirm, view, delete). When the form starts
out, it is in view mode....
|
by: Gary Davis |
last post by:
Freelance PHP programmer wanted, preferably in the Sarasota, Florida
area. Tampa, Orlando, Fort Myers areas also ok. Email Larry at
lkelleher at freedomvillage dot com.
x-- 100 Proof News - http://www.100ProofNews.com
x-- 30+ Days Binary Retention with High Completion
x-- Access to over 1.9 Terabytes per Day - $8.95/Month
x-- UNLIMITED DOWNLOAD
|
by: Mark Hahn |
last post by:
(I apologize in advance if this is not an appropriate posting)
I have written a simple windows shareware app, EzPicMailer, in Python 2.3,
wxPython 2.4.1, and PIL 1.1.4 that lets computer novices find photo files,
edit them, and mail them, all in one simple app. Everyone is encouraged to
check out my beta version at http://EzPicMailer.com.
I wrote it to be cross-platform except for a small amout of windows code to
do the system beep...
|
by: dreamcatcher |
last post by:
I wrote the following program which gets student id, and name, and
score, store them into a file,
use qsort() to sort the score, but seems when I wanted to inquire
specific student's info using id in inq(), i just never get what I
wanted, don't know why. thanx for point out my error.
#include <stdio.h>
| |
by: |
last post by:
Trying to learn about manipulating collections of objects, and populating
these objects dynamically from datasources. Could someone post a code sample
that shows the following:
Instantiating a collection object -- say, a dictionary.
Populating that collection object with custom objects, say, Person. What I
really want to see is how to populate the properties of those Person objects
from a datasource: instantiate one Person, fill...
|
by: KRUNOPOPOVIC |
last post by:
Hi,
I made new screen saver ElasticField in (unmanaged c++/directx)/c#.
Please try it:
http://www.geocities.com/krunopopovic/
and tell me your oppinion.
|
by: imghani |
last post by:
Hi all,
I have developed an application in ASP.NET. I wanted that whenever a
user comes to my website, it opens browser in F11 mode.
I find the code to open browser in F11 mode (its javascript) but this
can be done in window.open method of javascript, but i don't want to
open a new window instead wanted that existing window opens as full
screen (as through F11).
Did some R & D but get no such solution, so what trick i decided to do
is:
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |