|
I hadn't thought of that, I will add it to my testing. Thanks
|
|
|
|
|
I have a label that is based on a conditional statement, however, the condition is not acting correctly, for instance knowing that the following should be true:
A==1?"First":A==2?"Second":"Final"
Given 1, you see "First"
Given 2, it shows "Final"
Given any other number it shows "Final"
I need it to show "Second"
Now you see the pseudo code, here is the actual code:
<asp:Label ID="lblActive" runat="server" Text='<%# Convert.ToInt32(Eval("Active"))==1?"Active":Convert.ToInt32(Eval("Active"))==2?"Exempt":"Inactive" %>'></asp:Label>
Why is it always showing "Inactive" when clearly the eval is 2 or 1, I expected all the 0's to be Inactive and they are, but all 1's are active and all 2's are showing "Inactive"
|
|
|
|
|
Your sample code works for me:
for (int A = 1; A < 4; A++)
{
Console.WriteLine(A == 1 ? "First" : A == 2 ? "Second" : "Final");
} Generates:
First
Second
Final So I would suspect you need to look elsewhere in your code to identify what Eval("Active") is returning, and why.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
The syntax is correct.
The reason is very simple. It is always showing "Inactive" because the Convert.ToInt32(Eval("Active"))may not have assigned a value. If you are reading this values from you class file. You need to check where you assign the value.
Explaining further, If you assign a value to the "Active" in or after Page_Load() event, that will not be reflected in your aspx page(unless you Rebind() the controls again). You need to consider the ASP.Net Page cycle and related events. The controls should be rendered and assigned in proper sequence.
|
|
|
|
|
Hi,
I have a imaging software where we display the images.
We have different tools called as parameters in the UI.
Few of the parameters are namely:
1. Colors
2. Image thickness
3. Change image informations and so on...
The color parameter is used to change the color of the image,
the image thickness parameter is used to change the thickness of the image,
the change image information tool is use to change the image information like name, date of scaned etc.
Requirement:
If user changes any of the parameter, we need to notify the user with a * in the UI saying
one of the parameter has changed.
Class Design:
I want to implement a observer design pattern using events existing in the parameter clases.
Question:
I read observer design pattern. I had seen it using without
events. And also the definition says that
It defines a one-to-many dependency between objects so that when one object changes state, all its dependents
are notified and updated automatically.
But in my case I have many object and in change of any object I have to notify one object. Its actually
not one to many but many to one relationship.
Can I use observer design pattern in this ?? Can you specify which class shoud have attach, detach and notify
and which class should have update ??
Any help would be highly appreciated.
Thanks.
|
|
|
|
|
The most obvious answer for me is that you should have the classes that contain these changing properties implement INotifyPropertyChanged event, and raise a PropertyChanged event when your properties change. Taking your example, suppose you had a class structure that looked a bit like this interface hierarchy:
public interface IImage
{
Color Color { get; set; }
Thickness Thickness { get; set; }
IInformation Information { get; }
}
public interface IInformation
{
DateTime Scanned { get; set; }
string Details { get; set; }
} Well, you would want to raise a property changed event for the Color, Thickness, Scanned and Details changes. Then, all you would need to do in the class that was listening to this was have a PropertyChanged subscriber for the IImage implementation and one listening to the PropertyChanged event of the IInformation. Something like this would do it:
private IImage _image = new ImageImplementation();
private SetupEventHanders()
{
_image.PropertyChanged += MyPropertyChangedEventHandler;
_image.Information.PropertyChanged += MyPropertyChangedEventHandler;
}
private void MyPropertyChangedEventHandler(object sender, PropertyChangedEventArgs e)
{
IsDirty = true;
} Okay, this is a relatively naive solution, but it should give you some ideas of where to start. If you want to go the full observable route, you'll want to look into using RX. You might get some ideas here[^].
|
|
|
|
|
I don't understand the perpose of using abstract in c#,we can't create instance of abstract class and we also not define the method so why we use this?what is special thing which we not do by normal class?plz help me
|
|
|
|
|
An abstract class must be inherited from to be usable. What this means is that it's possible to define certain functionality that is common in inherited classes, saving you from having to write it again. A common example, in WPF, is a base ViewModel class that implements INotifyPropertyChanged:
public abstract class BaseViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string property)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(property));
}
}
} Now, you're free to use this wherever you need:
public class MyViewModel : BaseViewModel
{
private string _name;
public string Name
{
get { return _name; }
set
{
if (_name != value)
{
_name = value;
RaisePropertyChanged("Name");
]
}
}
}
modified 11-Jun-14 15:18pm.
|
|
|
|
|
Except you forgot to make BaseViewModel an abstract class!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
Member 10878790 wrote: we can't create instance of abstract class
That's why.
Some base classes can be used on their own, others can't -- if a base class is unusable by itself, and you don't want anyone to instantiate it, then mark it abstract. You don't have to (unless it contains abstract members), but it shows intent.
You'll never get very far if all you do is follow instructions.
|
|
|
|
|
I am changing the timezone and want to display the zone like this 1/14/12 4:52:50 AM PST
with the code i am not able to get exactly the output that i want. How can i get time along wit PST in the end
var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
var offset = timeZoneInfo.GetUtcOffset(DateTime.Parse(newRX.Header.SentTimeOffset));
var dto = new DateTimeOffset(DateTime.Parse(newRX.Header.SentTimeOffset), offset)
|
|
|
|
|
There's no real inbuilt mechanism for writing out an abbreviated TimeZone. You might want to try this[^] library though.
|
|
|
|
|
Hi,
I would like to ask the following:
I have a client who has a PC used for front office.
At the front office, he wants to keep LCD showing his products.
Is it possible to have my .net application running on the front office PC and display the products on the LCD (let’s call it PromoLCD) without interrupting the front office work? So users will continue using the front office PC for their own applications, work, excel, etc but only my application will be shown on PromoLCD?
Is this possible?
What’s your advise?
Thanks,
Jassim
Technology News @ www.JassimRahma.com
|
|
|
|
|
I wouldn't: any accidental "slip" by the front office users could result in an...um...unwanted...display.
Have you considered looking at something like a video file, or a photo slideshow? Use anything with HMDI and you could plug a Chromecast in and stream anything you wanted to it. Or most TV's now include a USB connector from which you could do much the same thing.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
It's possible not not a wise thing to do.
It's not so much this application screwing with the user of the machine, but the other way around.
This is normally done as a seperate, usually secured, workstation that is attached to it's own monitor and this LCD (monitor). The displays are setup so they mirror each other. What you see on the local monitor is what you see on the remote monitor.
Where I work, there's dozens of large format monitors spread throughout various areas that display company news information. They are all driven off a single PC that is connected to both a local monitor and a video system that all of these monitors are connected to. Bascially, its kind of like our own internal cable TV network.
|
|
|
|
|
A place I used to work at had LCD displays onto which you uploaded data to be displayed, which was stored in the display's internal memory. The PC was only needed for a short time to set up the data to be displayed, then upload it to the display.
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
I Connect to a MySql Server from my C# Winform Application and I use a DataReader and the Convert Method to read a DateTime variable from the DB and convert it(No Errors).
DateTime date = Convert.ToDateTime(rdr["LastContacted"].ToString());
However when I wish to display the DateTime fields from my DB in a DataGridView
I receive the error "Unable to convert MySQL date/time value to System.DateTime".
string sql = "SELECT ID,";
if (chbxName.Checked) sql += "MemberName, ";
if (chbxSurname.Checked) sql += "MemberSurname, ";
if (chbxCellNumber.Checked) sql += "CellNumber, ";
if (chbxTellNumber.Checked) sql += "TellNumber, ";
if (chbxEmail.Checked) sql += "Email, ";
if (chbxStreetAdress.Checked) sql += "Street, ";
if (chbxSuburb.Checked) sql += "Suburb, ";
if (chbxCity.Checked) sql += "City, ";
if (chbxOccupation.Checked) sql += "Occupation, ";
if (chbxTitle.Checked) sql += "Title, ";
if (chbxInitials.Checked) sql += "Initials, ";
if (chbxDateJoined.Checked) sql += "DateJoined , ";
if (chbxDateResigned.Checked) sql += "DateResigned, ";
sql = sql.Remove(sql.Length - 2, 2);
if (Type == "resignedmembers")
sql += " FROM resignedmembers";
else
sql += " FROM members";
sql += " WHERE MemberType = '" + Type + "' AND " + FilterParameter + " LIKE '%" + txtFilterQuery.Text + "%' ";
MySqlDataAdapter daClients = new MySqlDataAdapter(sql, cnManageMembers);
daClients.Fill(dtClients);
BindingSource bsClients = new BindingSource();
bsClients.DataSource = dtClients;
dgvClients.DataSource = bsClients;
bnClients.BindingSource = bsClients;
dgvClients.Columns[0].ReadOnly = true;
How do I resolve this and do I resolve it in my Application or DB?
Thank you for your time.
|
|
|
|
|
"DateTime date = Convert.ToDateTime(rdr["LastContacted"].ToString());"
Don't do that; just cast the value:
DateTime date = (DateTime) rdr["LastContacted"];
However, MySql is able to store "zero dates":
mysql> SELECT MIN(`acquisition`) FROM `v_array`
-> ;
+--------------------+
| MIN(`acquisition`) |
+--------------------+
| 0000-00-00 |
+--------------------+
1 row in set (0.05 sec)
which can be neither represented in a .net DateTime nor stored in Sql Server
System.Data.DataException: Exception encountered in ExecuteDataTable ---> MySql.Data.Types.MySqlConversionException: Unable to convert MySQL date/time value to System.DateTime
I have had to deal with this many times over the last couple of years (Oracle's Date type also exceeds what Sql Server can hold) so what I do is test and replace with NULL:
, CASE WHEN `acquisition`<'1753/1/1' THEN NULL ELSE `acquisition` END `acquisition`
'1753/1/1' is the minimum date that Sql Server (2012) can hold.
http://msdn.microsoft.com/en-us/library/system.data.sqltypes.sqldatetime(v=vs.110).aspx[^]
You may choose a different date if you like.
You'll never get very far if all you do is follow instructions.
|
|
|
|
|
PIEBALDconsult wrote: I have had to deal with this many times over the last couple of years (Oracle's Date type also exceeds what Sql Server can hold) so what I do is test and replace with NULL:
, CASE WHEN `acquisition`<'1753/1/1' THEN NULL ELSE `acquisition` END `acquisition`
Thank you, understood.
However how would I implement this? do I add the above code to my sql statement?
|
|
|
|
|
How about:
if (chbxDateJoined.Checked) sql += "CASE WHEN DateJoined < '1753/1/1' THEN NULL ELSE DateJoined END DateJoined , ";
You'll never get very far if all you do is follow instructions.
|
|
|
|
|
|
PIEBALDconsult wrote: However, MySql is able to store "zero dates" Even worse: February 29 is valid for any year (not restricted to leap years), and any month can have 31 days, and a day or month number of 0 is also valid (at least with older versions of MySQL, not sure about the current version).
|
|
|
|
|
Hadn't seen that. And it also seems that it only does Unicode. Fortunately, I only have to deal with one source in MySql.
You'll never get very far if all you do is follow instructions.
|
|
|
|
|
I am trying to get bytes sent and received in a Windows Store App but I am always getting bytes sent/received as zero. Code snippet is shown below. Any help/hint is highly appreciated, thank you
ConnectionProfile connectionProfile = NetworkInformation.GetInternetConnectionProfile();
if (connectionProfile.NetworkAdapter.IanaInterfaceType == (int)EnumMediaType.WiFi)
{
NetworkUsageStates nus = new NetworkUsageStates();
nus.Roaming = TriStates.No;
nus.Shared = TriStates.Yes;
TimeSpan TimeDiff = new TimeSpan(1, 0, 0);
IReadOnlyList<NetworkUsage> listNetworkUsage = await connectionProfile.GetNetworkUsageAsync(startTime.Subtract(TimeDiff), DateTimeOffset.Now, DataUsageGranularity.Total, nus);
for (int i = 0; i < listNetworkUsage.Count; i++)
{
textBoxMediaType.Text = string.Format("Sent: {0}, Received: {1}, Duration: {2}", listNetworkUsage[i].BytesSent, listNetworkUsage[i].BytesReceived, listNetworkUsage[i].ConnectionDuration);
}
Note: I am using IE in the background to download some pages to ensure that bytes are sent/received.
modified 11-Jun-14 9:38am.
|
|
|
|
|