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

For Karunakararo, re translate to C#

> hi Morten

i have problem with Datagrid paging .
After 10 pages it's giving Like 1 2 3 4 5 6 7 8 9 10 ...... these dot values iam converting to >> (like this) in VB.net
please see this function
Sub CustomPager(ByVal STCPagerGrid As Object)
Dim intCtr As Integer
Static intLastItem As Integer
Static intCount As Integer
Static intTotalPage, lintCurrentPage As Integer

For intCtr = 0 To STCPagerGrid.Controls.Count - 1

If STCPagerGrid.Controls(intCtr).GetType.ToString =
"System.Web.UI.WebControls.DataGridLinkButton" Then
If IsNumeric(STCPagerGrid.controls(intCtr).text) = True
And Left(STCPagerGrid.controls(intCtr).text, 1) <> "[" Then
STCPagerGrid.controls(intCtr).text = "[" &
STCPagerGrid.controls(intCtr).text & "]"
If STCPagerGrid.Controls(intCtr).Text = "..." And intCtr
= 0 Then
STCPagerGrid.Controls(intCtr).Text = "[<<]"
End If
If STCPagerGrid.Controls(intCtr).Text = "..." And intCtr
0 Then

STCPagerGrid.Controls(intCtr).Text = "[>>]"
End If
End If
If STCPagerGrid.controls(intCtr).controls.count > 0 Then
CustomPager(STCPagerGrid.controls(intCtr))
End If
Next
End Sub

how to write in C#


Well, for one, you can't use STCPagerGrid for much as long as it is an object. You need to either change the parameter to something else, like Control, or cast it to something like Control inside the method.

You can't use method local static variables in C# (to my knowledge). If you need to use static variables declare them outside the method.

There is no IsNumeric method in C#. The closest equivalent is probably Double.TryParse which is slightly more complex, and in the code below I haven't checked if you can set the numberformatprovider to null as I did.

There is no Left method in C#, use String.SubString(0, number of characters).

The translated code ended up a bit messy so I took the liberty to rewrite it a bit. The functionality should be the same or even perhaps slightly better.

public void CustomPager(object STCPagerGrid)
{
if(!(STCPagerGrid is Control))
return;

Control ctr = (Control)STCPagerGrid;
for(int intCtr = 0; intCtr < ctr.Controls.Count; intCtr++)
{
Control c = (Control)ctr.Controls[intCtr];
if(c.GetType().ToString() == "System.Web.UI.WebControls.DataGridLinkButton" )
{
double d;
bool isNumber = Double.TryParse(c.Text, System.Globalization.NumberStyles.Any, null, out d);

if(isNumber && c.Text.Substring(0, 1) != "[")
c.Text = "[" + c.Text + "]";
else if(c.Text == "..." && intCtr == 0)
c.Text = "[<<]";
else if(c.Text == "..." && intCtr > 0)
c.Text = "[>>]";
}

if(c.Controls.Count > 0)
CustomPager(c);
}
}
Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #1
3 1095
Morten,

You can use static IsNumeric method by setting a reference to
Microsoft.VisualBasic.dll and then calling the method on the Information
class in the Microsoft.VisualBasic namespace. You can access the Left
function as well on the Strings class, but since there is such an obvious
translation, I wouldn't bother. IsNumeric, however, has some very specific
logic which is not easily replicated with TryParse.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:opr8j3mvk4klbvpo@morten_x.edunord...
hi Morten

i have problem with Datagrid paging .
After 10 pages it's giving Like 1 2 3 4 5 6 7 8 9 10 ...... these dot values iam converting to >> (like this) in VB.net
please see this function
Sub CustomPager(ByVal STCPagerGrid As Object)
Dim intCtr As Integer
Static intLastItem As Integer
Static intCount As Integer
Static intTotalPage, lintCurrentPage As Integer

For intCtr = 0 To STCPagerGrid.Controls.Count - 1

If STCPagerGrid.Controls(intCtr).GetType.ToString =
"System.Web.UI.WebControls.DataGridLinkButton" Then
If IsNumeric(STCPagerGrid.controls(intCtr).text) = True And Left(STCPagerGrid.controls(intCtr).text, 1) <> "[" Then
STCPagerGrid.controls(intCtr).text = "[" &
STCPagerGrid.controls(intCtr).text & "]"
If STCPagerGrid.Controls(intCtr).Text = "..." And intCtr = 0 Then
STCPagerGrid.Controls(intCtr).Text = "[<<]"
End If
If STCPagerGrid.Controls(intCtr).Text = "..." And
intCtr
0 Then

STCPagerGrid.Controls(intCtr).Text = "[>>]"
End If
End If
If STCPagerGrid.controls(intCtr).controls.count > 0 Then
CustomPager(STCPagerGrid.controls(intCtr))
End If
Next
End Sub

how to write in C#


Well, for one, you can't use STCPagerGrid for much as long as it is an

object. You need to either change the parameter to something else, like
Control, or cast it to something like Control inside the method.
You can't use method local static variables in C# (to my knowledge). If you need to use static variables declare them outside the method.
There is no IsNumeric method in C#. The closest equivalent is probably Double.TryParse which is slightly more complex, and in the code below I
haven't checked if you can set the numberformatprovider to null as I did.
There is no Left method in C#, use String.SubString(0, number of characters).
The translated code ended up a bit messy so I took the liberty to rewrite it a bit. The functionality should be the same or even perhaps slightly
better.
public void CustomPager(object STCPagerGrid)
{
if(!(STCPagerGrid is Control))
return;

Control ctr = (Control)STCPagerGrid;
for(int intCtr = 0; intCtr < ctr.Controls.Count; intCtr++)
{
Control c = (Control)ctr.Controls[intCtr];
if(c.GetType().ToString() == "System.Web.UI.WebControls.DataGridLinkButton" ) {
double d;
bool isNumber = Double.TryParse(c.Text, System.Globalization.NumberStyles.Any, null, out d);
if(isNumber && c.Text.Substring(0, 1) != "[")
c.Text = "[" + c.Text + "]";
else if(c.Text == "..." && intCtr == 0)
c.Text = "[<<]";
else if(c.Text == "..." && intCtr > 0)
c.Text = "[>>]";
}

if(c.Controls.Count > 0)
CustomPager(c);
}
}
Happy coding!
Morten Wennevik [C# MVP]

Nov 16 '05 #2
On Tue, 25 May 2004 09:02:11 -0400, Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> wrote:
Morten,

You can use static IsNumeric method by setting a reference to
Microsoft.VisualBasic.dll and then calling the method on the Information
class in the Microsoft.VisualBasic namespace. You can access the Left
function as well on the Strings class, but since there is such an obvious
translation, I wouldn't bother. IsNumeric, however, has some very specific
logic which is not easily replicated with TryParse.


The documents say it will try to convert an object of type Short, Integer, Long, Decimal, Single, or String to a Double so I thought of using Double.TryParse, now realising it will only parse strings. However using ToString, won't that give it the exact same functionality, and more? In this context the parameter will always be string (Control.Text)

object o1 = 1;
object o2 = "2";
object o3 = "0x3af9"; // fails
object o4 = 0.5f;

double d;
Double.TryParse(o#.ToString(), NumberStyles.Any, null, out d) + " : " + d.ToString());

o1, o2, o4 works, but o3 fails. Does this work with IsNumeric?
--
Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #3
Morten,

0x3af9 will return false with IsNumeric. However, a VB programmer will
typically not use 0x3af9 to represent a hex number, they will use &h3af9,
which IsNumeric will return true on. VB6 returns false as well using
0x3af9, while returning true for &h3af9.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:opr8j5c5r2klbvpo@morten_x.edunord...
On Tue, 25 May 2004 09:02:11 -0400, Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> wrote:
Morten,

You can use static IsNumeric method by setting a reference to
Microsoft.VisualBasic.dll and then calling the method on the Information
class in the Microsoft.VisualBasic namespace. You can access the Left
function as well on the Strings class, but since there is such an obvious translation, I wouldn't bother. IsNumeric, however, has some very specific logic which is not easily replicated with TryParse.
The documents say it will try to convert an object of type Short, Integer,

Long, Decimal, Single, or String to a Double so I thought of using
Double.TryParse, now realising it will only parse strings. However using
ToString, won't that give it the exact same functionality, and more? In
this context the parameter will always be string (Control.Text)
object o1 = 1;
object o2 = "2";
object o3 = "0x3af9"; // fails
object o4 = 0.5f;

double d;
Double.TryParse(o#.ToString(), NumberStyles.Any, null, out d) + " : " + d.ToString());
o1, o2, o4 works, but o3 fails. Does this work with IsNumeric?
--
Happy coding!
Morten Wennevik [C# MVP]

Nov 16 '05 #4

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

Similar topics

7
by: Bengt Richter | last post by:
Just thought None as the first argument would be both handy and mnemonic, signifying no translation, but allowing easy expression of deleting characters, e.g., s = s.translate(None,...
1
by: shank | last post by:
I'm sure this is a stretch, but is there some kind of component that I could install to translate from English to Spanish on the fly? I have a lot of equipment features and specifications that I...
4
by: Gadrin77 | last post by:
I have data that looks like <Root> <Main Value="Line1|Line2.|Line3|Line4.|Line5"/> </Root> I'm using Translate(@Value, "|.", ",")
6
by: bobueland | last post by:
The module string has a function called translate. I tried to find the source code for that function. In: C:\Python24\Lib there is one file called string.py I open it and it says
6
by: Anders K. Olsen | last post by:
Hello group I'm trying to list the users and groups who has read access to a file. I use .NET 2.0 and FileInfo.GetAccessControl().GetAccessRules(...) and then loop through the...
1
by: peterbe | last post by:
This has always worked fine for me. Peter fine Now if I do it with a unicode string: Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib/python2.4/string.py", line...
9
bvdet
by: bvdet | last post by:
I have done some more work on a simple class I wrote to calculate a global coordinate in 3D given a local coordinate: ## Basis3D.py Version 1.02 (module macrolib.Basis3D) ## Copyright (c) 2006...
1
by: =?Utf-8?B?R2F1cmF2?= | last post by:
Hi, I am using the Translate() function in one of the .XSLT file to remove the spaces, like this: <xsl:for-each select=".//Illustration"> <xsl:value-of select="translate(./@illusName, ' ',...
3
by: Kenneth McDonald | last post by:
I have the need to occasionally translate a single word programatically. Would anyone have a Python script that would let me do this using Google (or another) translation service? Thanks, Ken
4
by: kovariadam | last post by:
Hi, Does anybody know why i get this error: SQL0176N The second, third or fourth argument of the TRANSLATE scalar function is incorrect. SQLSTATE=42815 with this query: SELECT...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...

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.