Wednesday, September 24, 2008

VB.NET Imports Alias

In case of you missed Python 'import as' :-)
Here the VB.NET equivalent

Imports cfg = System.Configuration.ConfigurationSettings

http://weblogs.asp.net/eporter/archive/2003/08/12/23892.aspx

Control ID Naming in Content Pages

The renaming id when using Master Pages
can be a pain
Here is an article to get out of it
http://www.asp.net/LEARN/master-pages/tutorial-05-vb.aspx

Monday, September 22, 2008

Filling a dropdownlist with LINQ


Partial Public Class _Default
Inherits System.Web.UI.Page

Dim northwind As New northwindDataContext()

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Not IsPostBack Then
Dim categories = From categorie In northwind.Categories _
Select categorie
DropDownList1.DataSource = categories
DropDownList1.DataTextField = "CategoryName"
DropDownList1.DataValueField = "CategoryID"
DropDownList1.DataBind()
End If

End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim selectValue = DropDownList1.SelectedItem.Value
Dim products = From product In northwind.Products _
Where product.CategoryID = selectValue
GridView1.DataSource = products
GridView1.DataBind()
End Sub

End Class

The ASPX Page

<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="Button" />
<br />
<hr />
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</div>
</form>
</body>

Transmit Forms Data to another ASP.NET page

A dicscussion a bout this problem
http://www.velocityreviews.com/forums/t67347-how-aspnet-page-gets-user-input-from-another-aspnet-page.html
And from Microsoft
http://msdn.microsoft.com/msdnmag/issues/03/04/ASPNETUserState/default.aspx

Sunday, September 21, 2008

LINQ to XML

Simple Query Sample


Module Module1

Sub Main()
Dim doc = XDocument.Load("c:\books.xml").Elements
Dim query = From data In doc.Elements _
Where data.Element("title") = "Python"
For Each g In query
Console.WriteLine(g.Element("author").Value)
Next
Console.ReadLine()
End Sub

End Module

Sample File

<books>
<book><title>Python</title><author>Guido</author></book>
<book><title>Haskell</title><author>Books</author></book>
</books>

LINQ to XML Samples

A few samples on querying XML with LINQ
http://www.thomasclaudiushuber.com/blog/tag/linq/

Creating Custom Configuration Sections in Web.config

From Scott Mitchell

http://aspnet.4guysfromrolla.com/articles/020707-1.aspx