Bunch's Blog

One day I'll have a catchy subtitle, one day
posts - 87 , comments - 120 , trackbacks - 0


There are 17 entries for the tag VB.Net
Using Table Valued Parameters

In SQL Server 2008 you can use table valued parameters which can be pretty useful. In the example I use a very simple one to overcome SQL Server’s lack of having a parameter as an array. The example goes through creating the new type, using it in a stored procedure and calling it from an application (VB.Net in this example). You start off with creating the new type. Under Programmability/Types/User-Defined Table Types create a new table. Here I created a table with a single column to hold an int

Posted On Thursday, November 3, 2011 8:05 AM | Comments (2) |

XmlWriter Formatting
Setting up formatting when using a XmlWriter is pretty easy. Declare a XmlWriterSettings variable and set the formatting options you want. The two main items are for indenting and new lines. You add the XmlWriterSettings variable as the second parameter in the XmlWriter.Create function. VB.Net Example Dim mySettings As New XmlWriterSettings() mySettings.Indent = True mySettings.NewLineOnAttributes = True Using writer As XmlWriter = XmlWriter.Create("c:\test.x... settings) C# Example XmlWriterSettings ......

Posted On Monday, July 18, 2011 12:22 PM | Comments (0) |

Accessing Controls Within A Gridview
Sometimes you need to access a control within a GridView, but it isn’t quite as straight forward as just using FindControl to grab the control like you can in a FormView. Since the GridView builds multiple rows the key is to specify the row. In this example there is a GridView with a control for a player’s errors. If the errors is greater than 9 the GridView should display the control (lblErrors) in red so it stands out. Here is the GridView: <asp:GridView ID="gvFielding" runat="server" DataSourceID="sqlFielding" ......

Posted On Friday, June 17, 2011 9:44 AM | Comments (0) |

Short Circuiting Forgetfulness in VB.Net
If nobody else but me reads this that is OK, this is just something I forget from time to time when working in VB.Net. To short circuit an expression the && or || operators in many other languages are AndAlso or OrElse in VB.Net. Two really simple examples: If a > b AndAlso a < c Then If a > b OrElse a > c Then Technorati Tags: VB.Net ......

Posted On Monday, May 2, 2011 11:47 AM | Comments (0) |

Setting a drop down’s selected value fails
Recently I had an issue where I just could not set a drop down list’s selected value from the code behind. I set other drop down list’s selected values from the code behind with no problem. Just this one was giving me grief. So here is how I set the values normally (the drop down lists are inside a formview): VB.Net Dim ddl As DropDownList ddl = fvTest.FindControl("ddlWorks") ddl.SelectedValue = 5 C# DropDownList ddl; ddl = (DropDownList)fvTest.FindCo... int j = 5; ddl.SelectedValue ......

Posted On Wednesday, March 30, 2011 8:11 AM | Comments (0) |

Access Master Page Controls II
Here is another way to access master page controls. This way has a bit less coding then my previous post on the subject. The scenario would be that you have a master page with a few navigation buttons at the top for users to navigate the app. After a button is clicked the corresponding aspx page would load in the ContentPlaceHolder. To make it easier for the users to see what page they are on I wanted the clicked navigation button to change color. This would be a quick visual for the user and is ......

Posted On Wednesday, March 16, 2011 9:09 AM | Comments (0) |

Combining Multiple Values in a Single Field
Here is a simple way to combine values into one field using T-SQL. This method is particularly handy when you don’t know ahead of time how many values will be returned. This simple example would return a student’s name and list of professors (separated by commas). SELECT stu.FullName, (SELECT prof.FullName + ', ' FROM tblProfessors prof INNER JOIN tblStuProf stuprof ON prof.ProfID = stuprof.ProfID WHERE stuprof.StuID = 1234 FOR XML PATH('')) AS Professors from tblStudents stu where stu.StuID = 1234 ......

Posted On Monday, September 20, 2010 10:53 AM | Comments (1) |

Using the AJAX SlideShowExtender with database images

This post goes over how to display images stored in a database using the SlideShowExtender control. The examples use VB.Net (what I have to use at the office) and assumes that you are storing your images in a database, a way to retrieve the images from the database (e.g. stored procedure) and have AJAX setup in your ASP.Net project already. Also the example was based on retrieving images that are photos hence the names of some of the various functions, controls, etc.

Posted On Friday, September 17, 2010 9:51 AM | Comments (7) |

Accessing Master Page Controls
Sometimes when using Master Pages you need to set a property on a control from the content page. An example might be changing a label’s text to reflect some content (e.g. customer name) being viewed or maybe to change the visibility of a control depending on the rights a user may have in the application. There are different ways to do this but this is the one I like. First on the code behind of the Master Page create the property that needs to be accessed. An example would be: Public Property CustomerNameText() ......

Posted On Thursday, April 8, 2010 2:23 PM | Comments (0) |

Inserting a New Row into a Datatable
Adding a new row to a datatable in a specific position is a snap. The scenario in this case would be that you have a datatable filled via a stored procedure that is also used in other applications so it can not be altered. The datatable is used to populate a dropdownlist and that list needs to have the always popular ‘Select All’ option as the first item. To add this in you could use code like what is listed below after the datatable is populated from the stored procedure. The example uses two columns ......

Posted On Friday, October 30, 2009 12:36 AM | Comments (0) |

Updating Parameter Check
Every now and again you may come across an error when trying to update a database from a data driven control (i.e. gridview, formview) that is tied to a SQL or Object data source. The errors usually are along the lines of “Could not find xxx that has parameters” along with a list of those parameters. Or an error that states there are too many parameters being passed. Aside from looking for typos, counting or lining up the parameters I will use one of these techniques to try and narrow down what may ......

Posted On Friday, October 2, 2009 5:47 AM | Comments (0) |

Loading Data on a Ajax TabPanel Click
Here is one way to have data load only when a TabPanel is clicked. In my example I have an aspx page with a TabContainer, two TabPanels both with their own ObjectDataSources that fill GridViews. The first tab’s ObjectDataSource and GridView will run on the page load and that is fine since it would be the first thing a user sees. The overall idea is to have the ObjectDataSource for the second tab to not run on the page load and then have the GridView on the second tab databind only when the tab is ......

Posted On Friday, May 15, 2009 10:48 AM | Comments (2) |

Quick and Dirty Calendar Validation (Date Required)
Probably everyone has at one time or another had a form that needed some sort of date to be entered. If you are like me and use ASP.Net and want to use the ASP calendar control the asp validators don’t work. Well without some work arounds to the calendar control. However if you just needed to validate if the user clicked on a date in the calendar control you can just use the regular calendar control and a customvalidator like this. The calendar control: <asp:Calendar ID="caltest" runat="server" ......

Posted On Tuesday, February 17, 2009 3:00 PM | Comments (4) |

Tabbing Issue with AutoPostBack
Here was a little issue that caused some frustration. I have an app with an UpdatePanel and inside that are two Textboxes each with their own RequiredFieldValidator. Both Textboxes had AutoPostBack set to True. Also each used an OnTextChanged event to trigger some checks from the code behind. The issue was after entering a valid value in Textbox1 you could not tab directly to Textbox2. When you hit the tab key the cursor would blink once in Textbox2 and then disappear. If you kept hitting tab the ......

Posted On Thursday, September 18, 2008 3:17 PM | Comments (0) |

JavaScript: Hurdling the ScriptManager
This piece of code is related to a previous post of JavaScript Window from Code Behind. The idea is the same; I needed to get some JavaScript to run from the code behind. For this example it was to open a new window. The real difference with this and the previous post is using ScriptManager instead of ClientScript. VB.Net Code Dim strScript As String = "<script language='javascript'>" strScript += "window.open('URL Goes Here');" strScript += "</script>" ScriptManager.RegisterStart... ......

Posted On Friday, June 20, 2008 9:54 AM | Comments (1) |

Javascipt Window From Code Behind
Something that stumped me a few years ago was trying to code a Javascript window (i.e. alert, confirm) from the code behind. I’ve listed some code below on how I did it in VS2005 using VB. For VS2003 the idea is the same but use Page in place of ClientScript and remove the GetType(String) parameter. One thing you do lose when doing it this way is any execution control that goes along with let’s say a confirm window. The window will appear but the rest of the code in the code behind sub or void will ......

Posted On Thursday, May 15, 2008 9:53 AM | Comments (0) |

Cascading DropDowns within a FormView (Without AJAX)
This was something else that gave me fits recently. I have a web app that uses a formview, which wasn’t that big a deal to me. Until I tried to have the value in one dropdown affect the value(s) in a second dropdown. For my problem the first dropdown holds manufacturer names and then the second displays the models by the selected manufacturer in the first dropdown. I could get the dropdowns to load up proper on the first load based on a SQL query, but the issue came about when I was testing changing ......

Posted On Monday, March 10, 2008 2:29 PM | Comments (1) |

Powered by: