|
i think i have an idea of how im going to do it, i can do something like this:
public static string GetMD5Hash(string text)
{
using ( var md5 = MD5.Create() )
{
byte[] computedHash = md5.ComputeHash( Encoding.UTF8.GetBytes(text) );
return new System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary(computedHash).ToString();
}
}
var nums = new List<int> {1, 2, 3};
var result = string.Join(", ", nums);
var hash = GetMD5Hash(result);
|
|
|
|
|
There is this code that have a name in the table data and I have been asked to make that data red. Right now it is bold (strong). I need to add code to also make it appear read. How do I do this?
Here is the code in C#
<ItemTemplate>
<%#
Eval("AttorneyPartyID").ToString() != Eval("PartyID").ToString() ?
"<table><tr><td>" + Eval("AttorneyFullName") + "</td></tr>"
:
"Pro Se"
%>
</ItemTemplate>
|
|
|
|
|
Why are you inserting a single-cell table? Just wrap the value in a <span> or a <div> , and set a suitable CSS class on it.
You'll also need to HTML encode the value from the database, just in case.
<ItemTemplate>
<%#
Eval("AttorneyPartyID", "{0}") != Eval("PartyID", "{0}")
? "<div class=\"attorney-full-name\">" + HttpUtility.HtmlEncode(Eval("AttorneyFullName", "{0}")) + "</div>"
: "Pro Se"
%>
</ItemTemplate>
.attorney-full-name {
color: #a00;
font-weight: bold;
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
It is not a single-cell. I did not paste the whole table (ItemTemplate). The table has 5 rows and each row has a single (cell)
Here is the whole table
<asp:TemplateField HeaderText="Attorney" HeaderStyle-HorizontalAlign="Justify" ItemStyle-Width="25%" >
<ItemTemplate>
<%#
Eval("AttorneyPartyID").ToString() != Eval("PartyID").ToString() ?
"<table><tr><td>" + Eval("AttorneyFullName") + "</td></tr>"
:
"Pro Se"
%>
<%#
Eval("AttorneyPartyID").ToString() != Eval("PartyID").ToString() && Eval("AttorneyPhoneNumber") != "" && Eval("AttorneyPhoneNumber") != null ?
"<tr><td>Phone:" + ' ' + Eval("AttorneyPhoneNumber") + "</td></tr>"
:
string.Empty
%>
<%#
Eval("AttorneyPartyID").ToString() != Eval("PartyID").ToString() && Eval("AttorneyEmail") != "" && Eval("AttorneyEmail") != null ?
"<tr><td>Email:" + Eval("AttorneyEmail") + "</td></tr>"
:
string.Empty
%>
<%#
Eval("AttorneyPartyID").ToString() != Eval("PartyID").ToString() ?
"</table>"
:
string.Empty
%>
</ItemTemplate>
</asp:TemplateField>
|
|
|
|
|
You still need to HTML-encode the database values. And the solution to your original question is still the same: add a CSS class to the parent element of the text you want to style.
I also think you can tidy that code up somewhat, and avoid having to build the HTML as a string:
<asp:TemplateField HeaderText="Attorney" HeaderStyle-HorizontalAlign="Justify" ItemStyle-Width="25%">
<ItemTemplate>
<asp:MultiView runat="server" ActiveViewIndex='<%# Eval("AttorneyPartyID", "{0}") != Eval("PartyID", "{0}") ? 0 : 1 %>'>
<asp:View runat="server">
<table>
<tr>
<td class="attorney-full-name"><%#: Eval("AttorneyFullName") %></td>
</tr>
<asp:Placeholder runat="server" visible='<%# !string.IsNullOrEmpty(Eval("AttorneyPhoneNumber", "{0}")) %>'>
<tr>
<td class="attorney-phone-number">Phone: <%#: Eval("AttorneyPhoneNumber") %></td>
</tr>
</asp:Placeholder>
<asp:Placeholder runat="server" visible='<%# !string.IsNullOrEmpty(Eval("AttorneyEmail", "{0}")) %>'>
<tr>
<td class="attorney-email">Email: <%#: Eval("AttorneyEmail") %></td>
</tr>
</asp:Placeholder>
</table>
</asp:View>
<asp:View runat="server">
Pro Se
</asp:View>
</asp:MultiView>
</ItemTemplate>
</asp:TemplateField> NB: Using <%#: ... %> instead of <%# ... %> - note the extra : at the start - will automatically HTML-encode the output for you.
MultiView Class (System.Web.UI.WebControls) | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank for your help on trying to figure this out. I did add css class to existing css file.
.inactiveAttorney
{
color: #AD0000;
font-weight:bold
}
The product owner have asked me to only make the attorney name red when fActive = 0 (false). The code behind have this code
private bool _fActive;
public bool fActive
{
get { return this._fActive; }
set { this._fActive = value; }
}
this._fActive = parsefActive == true ? true : false;
I have successfully been able to use css class to make attorney name red. However, I need help to add a condition so that the name is red only when fActive =false (0).
Here is my code which is working and needs adding condition
"<table><tr><td class='inactiveAttorney'>" + Eval("AttorneyFullName") + "</td></tr></table>"
The fActive is a Boolean and else where in the code I see something done when a Boolean is true. I need to do something similar but I do not know how.
Here is that example.
<tr><td><%# (bool)Eval("PartyConfidentialHomePhone") == true ? "<img src=\"../../Images/YellowLock_16x16.png\" alt=\"Home Phone Secured\" />":"" %><%#Eval("PartyHomePhone").ToString() != "" && Eval("PartyHomePhone") != null ? "" + Eval("PartyHomePhone") + "":string.Empty%></td></tr>
modified 9-Mar-20 13:29pm.
|
|
|
|
|
Try:
"<table><tr><td class='" + (fActive ? "activeAttorney" : "inactiveAttorney") + "'>" + Eval("AttorneyFullName") + "</td></tr></table>"
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi Homer,
Thanks for your reply. When I tried the code you gave me, I am getting an error The name "fActive" does not exist in the current context
|
|
|
|
|
Then the code-behind of the page or user control where the data-binding is taking place doesn't have the property you showed in your previous message.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Here is the code behind that have the fActive
private bool _fActive;
public bool fActive
{
get { return this._fActive; }
set { this._fActive = value; }
}
bool parsefActive = false;Boolean.TryParse(row["fActive"].ToString(), out parsefActive);
this._fActive = parsefActive == true ? true : false;
|
|
|
|
|
As I said, that doesn't tally with the error message:
The name "fActive" does not exist in the current context
That property does not exist in the code-behind for the page or user control where your data-binding is taking place.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi everybody who tried to help me on this problem. I wanted to thank you for trying to help. However after hours of try and error, I found a solution that works. Just wanted to let you know this is now fixed. Here is my solution. Looks pretty simple! So the logic is, if AttorneyPartyID = PartyID that is Pro Se, else if fActive is false that means the attorney is inactive. Use inactiveAttorney css class to display attorney name with red font
else the attorney is active and no need to display name in red font. Display in bold font.
<%#
Eval("AttorneyPartyID").ToString() == Eval("PartyID").ToString()
? "Pro Se"
: (bool) Eval("fActive") == false
? "<table><tr><td class='inactiveAttorney'>" + Eval("AttorneyFullName") + "</td></tr>"
:"<table><tr><td>" + Eval("AttorneyFullName") + "</td></tr>"
%>
modified 12-Mar-20 10:22am.
|
|
|
|
|
Hi Experts,
I have a requirement to access a connected printer device through their embedded web server.
The device had an option to secure its details using username and password.
Once it is set, we can only communicate through "https" to that device.
Also there is windows credentials popup will come from UWP app once we initiate communication through https and wait for the user to enter the correct username and password as in web server.
My requirement is we need to pass those credentials as authorization header for a POST request to that device.
eg:-
Authorization: Basic YWRtaW46MTIzNDU2Nzg5
How to access those Windows credentials in UWP app. Without this authorization token, i am getting HTTP:401 unauthorized error for the POST request.
Please guide me to resolve this issue.
What I have tried:
I tried hard coding the username and password entered in the web server.
var username = usrName;
var password = pwd;
var base64String = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{username}:{password}"));
_httpClient.AuthorizationHeader = new KeyValuePair<string, string>("Basic", base64String);
then in this case the POST request is successful.
Also tried the same in a separate test application. In that case after entering the credentials in the windows credentials popup the same POST request is again sending automatically with those credentials as Basic auth token.
Regards
Spk
|
|
|
|
|
|
Ok. Sorry it's under the new tab. My mistake.
|
|
|
|
|
Hello experts
I have this behavior that I cannot figure it out. The following code loops through and extracts some firewall settings. It is triggered by a button
try
{
Type typeFWPolicy2 = Type.GetTypeFromProgID("HNetCfg.FwPolicy2");
INetFwPolicy2 fwPolicy2 = (INetFwPolicy2)Activator.CreateInstance(typeFWPolicy2);
foreach (INetFwRule rule in fwPolicy2.Rules)
{
lvItems.RuleName = rule.Name; ;
lvItems.RemoteAddress = rule.RemoteAddresses;
lvItems.Protocol = rule.Protocol.ToString();
lvItems.LocalPort = rule.LocalPorts;
dataGrid1.Items.Add(lvItems);
}
}
catch (Exception ex)
{
MessageBox.Show("something went wrong");
}
When I run it, the datagrid is populated with the same record (only the first) entry that is repeated several times.
then I added a MessageBox to troubleshoot, then Datagrid is populated correctly but I need to acknowledge each Messagebox !!!!. It is like it just needs that extra mouse click.
any help is greatly appreciated
|
|
|
|
|
You are overwriting the lvItems instance each time you go through the loop. You should move the instantiation of lvItems inside the loop so you have a new instance created each time.
|
|
|
|
|
That's because you add the same item each time round the loop. Unless you create a new instance of lvItems inside the loop, each time you go round you overwrite the values in the same one - so when you exit the loop, you have one item added five times, say - and they will all display the "latest value" which will be the last rule you processed inside the loop.
Add something like
lvItems = new TypeOfLVItemThatIDontKnowAndYouDo(); to the top of the loop, and it's use a different one each time.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
As the actual problem has already been pointed out, I will just add: Use a debugger.
Using a debugger is not something complicated you need to learn down the line. It is the first skill you need to acquire as it is really easy to lean - 5 minutes and you have the basic - and it will save you hours.
First look at the debugger - Visual Studio | Microsoft Docs[^]
|
|
|
|
|
I don't know exactly how to loop though the groupping in parallel. Currently I have the following code:
var lstFilters = dbLinq.Price
.GroupBy(g => g.Date.Year);
foreach (var group in lstFilters)
{
foreach (var item in group)
{
}
}
The code above is not working because of timeout and I don't know how could I run this like:
lstFilters.AsParallel().ForAll(chunks =>
{
});
|
|
|
|
|
Paralleling this isn't going to stop the timeout error.
It's telling you the database is taking too long to return results. This could be caused by a number of factors, not the least of which is a lot of data in a table where the data you're using isn't indexed.
|
|
|
|
|
@Dave,
The table is indexed with noncluster and cluster index (Sybase ASE). I've tried to setup the timeout but it's not working:
using (LinqDB dbLinq = new LinqDB(dbSource))
{
dbLinq.CommandTimeout = UniversalVariables.linqTimeOut;
}
In addition, when I changed the query and executed it with where clause passing each year it was not giving me this Timeout Error.
|
|
|
|
|
Is the Date column you're grouping on indexed? And how many records are we talking about?
|
|
|
|
|
|
Hi,
seems like a lot of data or a huge amount of processing per item is causing the one database operation to time out. I would work in smaller chunks, e.g. first determine the list of different years involved, then for each year do whatever is required. That would involve N+1 shorter database accesses, 1 for getting the distinct list, then N for getting and processing each year.
Only when the calculations you perform for each year are significant (vs their database access time) I would consider using parallelism. Which might not pay off when also a lot of UI operations are involved (which would make me doubt the UI is well designed...)
|
|
|
|