Archive for the ‘ Asp.net ’ Category

Hello, today you will learn how to add a default value such as “select a value” to the top of your bound dropdown list in vb.net. I am not going to show you how to bind your dropdown list, you can do that by searching this in google if you do not know how to do this.

After your dropdown list has been bound, you should use the following code after you close your connection to the database.

Dim Item As ListItem = New ListItem
Item.Text = “select a value”
Item.Value = “0″
Item.Selected = True
BoundDropDownList.Items.Insert(0, Item)

Hope this helps.

Dim strHockey As String = “vancouver canucks”
strHOckey = StrConv(strHockey, VbStrConv.ProperCase)
MsgBox(srtHockey)

Output will be Vancouver Canucks

Setup mysql with asp.net

Introduction

Back in the days of classic ASP, if you were building a database-driven web site, your choice was either to invest a lot of money to get a copy of Microsoft SQL Server (or some othe15 seconds enterprise-ready database) or invest a lot of time finding a way to deal with the performance and scalability limitations of Microsoft Access. Luckily these days there’s another viable alternative: MySQL.

Click here to get more information on how to set this up with asp.net.

So you want to separate your string using explode or join your string using implode in vb.net? Explode/implode are functions of the php environment and do not exist in asp.net therefore you must use the split() function to get your results for explode and join() for implode.

Split() Example

mystring = “hello;sir;how are you”;

arrayData=mystring.Split(mystring,”;”)

Result
arrayData(0) would equal “hello”
arrayData(1) would equal “sir”
arrayDate(2) would equal “how are you”

Join() Example

Dim JoinArray(3)

JoinArray(0) = "Welcome"
JoinArray(1) = "to"
JoinArray(2) = "Web Infinite"

Dim strSentence as String
strSentence = join(JoinArray)

Result
strSentence would equal to “Welcome to Web Infinite”

ASP.Net – Rewrite URL in VB.Net

Application_BeginRequest method of Global.asax file can be used to rewrite the URL of the current page.? Following code snippet shows you how to achieve this goal.

<%@ Application Language=?VB? %>
<script runat=?server?>

Protected Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)

?This is for dynamic redirection without having to create a directory in the root folder. We
?needed to change the 404 in IIS under custom errors to /(forward slash) instead of the default 404b.html

If Regex.IsMatch(Request.Url.AbsoluteUri, ?404;?) ?Get the url from browser address bar
Dim UrlSplit(), url as String
UrlSplit = Request.Url.AbsoluteUri.Split(??404;?) ?Split the url where the error occured in this case 404
url = replace(UrlSplit(1), ?404;?, ??)
url = replace(url, ?http://www.youraddress.com?, ??) ?Replaces the youraddress.com address and puts nothing

?Select Case to check where the page should be redirect too.
Select Case url
Case ?/aboutmypage?
response.Redirect(?/aboutus?) ? Redirects to correct url.
Case ?/yourprogram?
response.Redirect(?/programs/yourprogram?)
Case ?/canucks?
response.Redirect(?/sports/hockey/canucks?)
Case Else
response.redirect(?/help/sitemap/index.aspx?)
End Select
End If
End Sub

</script>