VB.NET 将字典绑定到ComboBox

'dDates is a Dictionary(Of Int32, String)
cmbDate.DataSource = New BindingSource(dDates, Nothing)
cmbDate.DisplayMember = "Value"
cmbDate.ValueMember = "Key"

VB.NET 用XML填写文件

' must include: Imports System.Web.HttpContext 

Dim DS As New DataSet()
      
        Dim FilePath As String
        ''AspEnableParentPaths = True
        'FilePath = Server.MapPath("~/App_Data/tlkpCodeValues.xml")
        FilePath = Current.Server.MapPath("App_Data\tlkpCodeValues.xml")

        DS.ReadXml(FilePath)
        
        Dim I As Integer
        strddl.Items.Clear()
        ' Display the result
        For I = 0 To DS.Tables(0).Rows.Count - 1
            If DS.Tables(0).Rows(I).Item("CodeType") = strObjParm Then
                Dim newListItem As New ListItem
                newListItem.Value = DS.Tables(0).Rows(I).Item("Code_Val")
                newListItem.Text = DS.Tables(0).Rows(I).Item("ShortDescText")
                strddl.Items.Add(newListItem)
            End If
        Next
        strddl.Items.Insert(0, New ListItem("--Choose One--"))

VB.NET 多个文件复制

Imports System.IO

Private Sub CopyFiles(ByVal sSource As String, ByVal sDestination As
String, Optional ByVal sExtension As String = "*.csv", Optional ByVal
blnOverWrite As Boolean = False)
If Directory.Exists(sSource) = False Then
MessageBox.Show("Source directory doesn't exist", "Source
Directory Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If Directory.Exists(sDestination) = False Then
MessageBox.Show("Destination directory doesn't exist",
"Destination Directory Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
Dim fil As FileInfo
Dim diSourceDir As New DirectoryInfo(sSource)
Try
For Each fil In diSourceDir.GetFiles(sExtension)
fil.CopyTo(Path.Combine(sDestination, fil.Name), blnOverWrite)
Next
Catch ex As Exception
' Probably read only
End Try
End Sub

VB.NET 从URL获取Google地图坐标

Public Function GetGeoCoords(ByVal inString As String) As String
   Dim Chunks As String()
   Dim outString As String = ""
   Chunks = Regex.Split(inString, "&")
   For Each s As String In Chunks
      If InStr(s, "ll") > 0 Then outString = s
   Next
   Return Replace(Replace(outString, "sll=", ""), "ll=", "")
End Function

VB.NET 从ObjectDataSource获取记录计数

Private Sub ObjectDataSource1_Selected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs) Handles ObjectDataSource1.Selected
Dim numRows As Integer = (e.ReturnValue).Tables(0).Rows.Count
End Sub

VB.NET 格式化电话号码

Dim pn As String = "(444) 444-444"
Dim newPn As String = Replace(Replace(Replace(pn, "-", ""), "(", ""), ")", "")
newPn = String.Format("{0:###-###-####}", Convert.ToInt64(newPn))

VB.NET 循环通过DataSet

For Each DataRow As DataRow In ds.Tables(0).Rows
   Dim outData as String
   outData = DataRow("fieldName").toString
Next

VB.NET 生成随机字符串

Public Function GenerateRandomString() As String
   GenerateRandomString= System.Guid.NewGuid.ToString
End Function

VB.NET 从.aspx页面调用MasterPage中的函数

CType(Me.Master, MasterPages_MasterPageName).FunctionOrSubName()

VB.NET 删除记录前的JavaScript确认警报

SomeButton.Attributes.Add("OnClick", "return(confirm('Are you sure you want to delete this record?'));")