Two ways of binding data to a GridView (ASP.NET)

In the following example, I will show you how to bind the same field to an ASP.NET GridView using two different methods.

In the first example, I utilize the an asp:BoundField to display the data, whereas in the second example I utilize an asp:TemplateField

Example 1 – BoundField:

[vb]

<asp:BoundField DataField=”ORDER_NUMBER” HeaderText=”Order” ReadOnly=”True” SortExpression=”ORDER_NUMBER” ItemStyle-Wrap=false />

[/vb]

Example 2 – TemplateField:

[vb]

<asp:TemplateField HeaderText=”Order” SortExpression=”OrderLineSched” ItemStyle-Wrap=”false”>
<ItemTemplate>
<asp:Label ID=”OrderLineSched” runat=”server” Text='<% #Bind(“ORDER_NUMBER”) %>’></asp:Label>
</ItemTemplate>
</asp:TemplateField>

[/vb]

Both will display exactly the same, however the TemplateField provides greater flexibility because if, for example, you change the field type from Label to TextBox, you can make it an editable field that will actually be editable in the entire GridView (all rows).

SELECT TOP SQL alternative for Oracle databases

When querying SQL Server databases you can return the top X number of records that match the query criteria via a SQL statement similar to the following:

[sql]SELECT TOP 100 * FROM tbl_Products WHERE Prod_Desc LIKE ‘*widget*'[/sql]

However, this same SQL statement will not run against an Oracle database because there is no built-in “TOP” function.  To get around this, you can utilize the ROWNUM pseudocolumn.  Example:

[sql]SELECT * FROM tbl_Products WHERE Prod_Desc LIKE ‘%widget%’ AND ROWNUM < 101[/sql]

How to increase or decrease font size in web browser

To make the font size larger in your web browser (Internet Explorer, Firefox, Chrome, Safari, etc.):

  • Windows PC: Press [Ctrl] + [+]
  • Mac: Press [Command] + [+]

To make the font size smaller in your web browser:

  • Windows PC: Press [Ctrl] + [-]
  • Mac: Press [Command] + [-]

To set the font size back to the “default” size for the web browser:

  • Windows PC: Press [Ctrl] + [0]
  • Mac: Press [Command] + [0]

Nick Tahou’s Meat Sauce Recipe

Ingredients

  • 1 medium onion, chopped
  • 1 teaspoon oil
  • 1 pound ground beef
  • 1 cup water
  • 1/4 cup tomato paste
  • 1 tablespoon brown sugar
  • 1 teaspoon black pepper
  • 1 teaspoon cayenne pepper
  • 1 teaspoon chili powder
  • 1/2 teaspoon ground cumin
  • 1/4 teaspoon allspice
  • 1/8 teaspoon ground cloves
  • salt to taste
  • 1 clove garlic, diced or pressed through a garlic press

Start with a crock pot put the oil, onions and garlic in the crock and turn it on high start adding all of the spices.  Mix this up well and add the tomato paste.  Mix well.  By now everything should be warm and the onions softening.  Add the ground beef raw, yes raw, and add water until the beef is almost covered. Put the lid on the crock for about 10 minutes.  Open the crock and stir, stir , stir until the beef looks fine and re-cover. Leave the heat on High until the water comes to a boil and then reduce the heat to Low. Cook for at least 3 hours. Keep moist with water; most will cook away.  Add more water as needed but don’t flood it. If needed, ladle-out the extra water when time to serve. This flavor should remind you more of the real thing. OM NOM NOM!

Source: http://www.chow.com/recipes/28498-nick-tahous-meat-sauce

Nacho Cheese Sauce Recipe

  • 2 tablespoons unsalted butter
  • 2 tablespoons all-purpose flour
  • 1 cup whole milk
  • 1 cup lager beer
  • 1 1/2 cups shredded sharp cheddar cheese
  • 1 1/2 cups shredded Monterey jack cheese
  • 2 teaspoons chili powder
  • 1 teaspoon smoked chipotle powder
  • 1/2 teaspoon paprika

Place a medium saucepan over medium heat and melt butter. When the butter is melted whisk in the flour until combined and cook, stirring frequently for 2 minutes. Slowly whisk in the milk and beer until combined. Bring the mixture to a simmer and continue to cook until the sauce has thickened. Reduce the heat to low and stir in the cheeses, spices and season with salt and pepper. Hold the sauce over low heat, stirring occasionally, until ready to serve.

Source: http://youtu.be/TIwgN2jhXQA

Xbox 360 Port Forwarding – Fix NAT Issue

This video quickly shows you how to setup your Xbox 360 to always have the same IP address on your local network as well as forwarding 4 ports on your Router to the Xbox.  This will help your Xbox connectivity and will resolve the issue if your NAT Type was listed as “Moderate” or “Strict.”

1. Open your Internet browser
2. Sign-in to your Router by entering your Router’s IP Address and clicking Enter.  If you don’t know how to determine your Router’s IP Address watch one of these videos to find out:

Mac OS X – http://www.youtube.com/watch?v=wVDFmFYZPhQ&hd=1
Windows 7 – http://www.youtube.com/watch?v=lMbW1qHI55w&hd=1
Windows XP – http://www.youtube.com/watch?v=igcDT3VSGoU&hd=1

3. Sign-in to your Router (if applicable) with your Router’s Administrator username and password
4. Click the DHCP Reservation button
5. Select the Xbox from the list of DHCP Clients; the Xbox will typically be the entry with no name
6. Click the Add Clients button
7. Provide a descriptive name for the Xbox
8. Change the IP Address reserved for the Xbox to something easy to remember; I used 192.168.1.160 in this example.  If you don’t change the IP Address, take note of what the address is before continuing
9. Click the Save Settings button
10. Click the Applications & Gaming tab
11. Enter the following 4 Ports and forward them to the Xbox’s IP Address that we just defined in step 8
Port 88 – UDP
Port 3074 – Both
Port 53 – Both
Port 80 – TCP
12. Make sure that all of the Port Forwarding rules have pointed to the Xbox and have all been enabled
13. Scroll to the bottom of your window
14. Click the Save Settings button
15. Click the Continue button

Microsoft Link with more information:
http://support.xbox.com/en-US/xbox-live/troubleshoot/connection-issues/nat-type-strict

How To Redeem iTunes Gift Card in iTunes

How To Redeem iTunes Gift Card in iTunes

  1. Open iTunes
  2. Click the iTunes Store icon on the left menu
  3. Click the Sign-In button in the top right (if you have not signed-in to the Apple Store on this Mac before)
  4. Enter your Apple ID and Password
  5. After you see your email address in the top right (where the Sign-In button was), click the Redeem option in the Quick Links section on the right
  6. Enter your iTunes Gift Card code
  7. Press the Redeem button

Export Data Grid (datagridview) to Excel in VB.NET

Create the following method and pass it the DataGridView that you want to export.  This will export all grid contents (including column headers) to Excel and “freeze” the top row.

Note: The “prog_Progress” object is a ProgressBar I added to the application to display the progress of the export to the user.

[csharp]

private void ExportDataGridViewToExcel(DataGridView dgv)
{
// exit method if there are no records to export
if (dgv.RowCount == 0)
{
MessageBox.Show(“No data to export.”, “No Data”, MessageBoxButtons.OK, MessageBoxIcon.Stop);
return;
}

SaveFileDialog fd = new SaveFileDialog();

fd.OverwritePrompt = false;
fd.FileName = “Export-” + DateTime.Now.ToString(“yyyyMMdd.hhmm”) + “.xls”; // default file name
fd.Filter = “Excel (*.xls) |*.xls;*.xlsx”;

if (fd.ShowDialog() == DialogResult.OK) // only continue if user specified/selected a file
{
UpdateStatus(“Exporting data to Excel…”);

// create the Excel app
Microsoft.Office.Interop.Excel._Application xlApp = new Microsoft.Office.Interop.Excel.Application();

// create the Workbook
Microsoft.Office.Interop.Excel._Workbook xlWB = xlApp.Workbooks.Add();

// create the Worksheet
Microsoft.Office.Interop.Excel._Worksheet xlWS = (Microsoft.Office.Interop.Excel._Worksheet)xlWB.Worksheets[1];

try
{
// show the progress bar
prog_Progress.Visible = true;
prog_Progress.Style = ProgressBarStyle.Blocks;
prog_Progress.Maximum = dgv.RowCount – 1;

// export the column headers
for (int c = 0; c < dgv.ColumnCount; c++)
{
xlWS.Cells[1, c + 1] = dgv.Columns[c].HeaderText;
}

// bold and underline the first row
Microsoft.Office.Interop.Excel.Range rng = (Microsoft.Office.Interop.Excel.Range)xlWS.Rows[1];
rng.EntireRow.Font.Bold = true;
rng.EntireRow.Font.Underline = true;

// freeze the top row
xlApp.ActiveWindow.SplitRow = 1;
xlApp.ActiveWindow.FreezePanes = true;

// export the data in the DataGridView
for (int r = 0; r <= dgv.RowCount – 1; r++)
{
Application.DoEvents(); // prevent the app from “Not Responding”…
prog_Progress.Value = r; // update the Progress Bar

for (int c = 0; c <= dgv.ColumnCount – 1; c++)
{
xlWS.Cells[r + 2, c + 1] = dgv[c, r].Value;
}
}

xlWS.Columns.AutoFit(); // autofit the columns

xlWB.SaveAs(fd.FileName); // save the file

prog_Shares.Visible = false;

xlWB.Close();
xlWS = null;
xlWB = null;
xlApp.Quit();
fd = null;

MessageBox.Show(“Excel Workbook Created Successfully”, “Export Complete”, MessageBoxButtons.OK, MessageBoxIcon.Information);
UpdateStatus(“Export to Excel complete!”);
}
catch (Exception ex)
{
xlWB.SaveAs(fd.FileName); // save the file
xlApp.Quit(); // quit Excel
prog_Progress.Value = prog_Shares.Maximum;
MessageBox.Show(“Error exporting data to Excel.” + Environment.NewLine + ex.Message, “Export error”, MessageBoxButtons.OK, MessageBoxIcon.Error);
prog_Shares.Visible = false;
}
}
}

[/csharp]