M
Morten Wennevik
hi Morten
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]
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 intCtrSTCPagerGrid.Controls(intCtr).Text = "[>>]"0 Then
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]