日期:2014-05-18  浏览次数:20605 次

请教用C#帮我实现下面程序的功能
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  ' Save DepartmentID from the query string to a variable
  Dim departmentId As String = Request.QueryString("DepartmentID")
  ' If no department is selected, this control should be invisible
  If IsNumeric(departmentId) Then
  Me.Visible = False
  ElseIf Not Page.IsPostBack Then
  ' Update the data grid
  BindDepartments()
  End If
  End Sub

------解决方案--------------------
Private void Page_Load(Object sender, EventArgs e)
{
 string departmentId = Request.QueryString("DepartmentID");
 if (IsNumeric(departmentId))
 {
Me.Visible = false;
 }
 else if(!Page.IsPostBack)
 {
BindDepartments()
 }
}
------解决方案--------------------

MyBase.Load +=Page_Load;
Private Page_Load(System.Object sender ,System.EventArgs e )
{
// Save DepartmentID from the query string to a variable 
String departmentId = Request.QueryString("DepartmentID").toString(); 
// If no department is selected, this control should be invisible 
If (IsNumeric(departmentId))
Me.Visible = False ;
ElseIf(!Page.IsPostBack) 
//Update the data grid 
BindDepartments() ;
 }
//这样?
------解决方案--------------------
IsNumeric方法,c#中没有的。但
可以用正则表达式判断,同样的效果
------解决方案--------------------
C# code

if (!String.IsNullOrEmpty(string变量) && !System.Text.RegularExpressions.Regex.IsMatch(string变量, "\\D")

------解决方案--------------------
C# code
public class

------解决方案--------------------
Private void Page_Load(Object sender, EventArgs e) 

 string departmentId = Request.QueryString("DepartmentID"); 
 if (IsNumeric(departmentId)) 
 { 
Me.Visible = false; 
 } 
 else if(!Page.IsPostBack) 
 { 
BindDepartments() 
 } 
}

try
{
convert.todouble(departmentId);
Me.Visible = false; 

}
catch
{
if(!Page.IsPostBack) 
 { 
BindDepartments() 
 } 
}