Skip to main content

Posts

Showing posts from September, 2009

Grids and ASP.NET (vb)

Manually filling rows of data in ASP.NET controls can be a bit unintuitive. I’ll go over a few things I learned recently. I’m writing up this posting off the top of my head, so I can’t say for certain the code examples are correct in syntax. Use the template field in your grid view as it’s the most flexible to deal with as apposed to using asp bind field tags or other means. <asp:TemplateField HeaderText="A Column"> <ItemTemplate> <a href="http://address"><%# Bind("dbField") %></a> </ItemTemplate> </asp:TemplateField> The example above is a column template field with the Bind() function call. Bind() is a special function that can be used to link data that the template field has access to within the grid row. You can also use Eval() which just prints the data and does not hard link the control and data like Bind() does. Also take note of the # in the asp tags <%# %> this is shorthand for...

Short-circuit conditionals in VB.NET

I’m in a situation now where I am required to write programming code in VB.NET. Which brings me up to a simple programming construct that I came upon by writing code like I would in C#, but getting a different expected result in VB.NET. In C#, using the && operator in conditionals is *by default* a short-circuit type conditional. That means when the first term is evaluated, the additional statements won’t be processed at all if that first statement was not true. The main benefit is something like this: Say, you want to check a listbox for specific values… if(lb1.selectedIndex > -1 && lb1.selectedValue.compare(“value text”) == true) { code to run } If the list box has no list items in there (eg. a selectedIndex of -1), the second condition will never be checked. If C# did not short circuit after the first term resulted in false, a program error would occur because the second condition would not have anything set for the selectedValue property. Oddly enough, in VB...