Skip to content

Instantly share code, notes, and snippets.

View drobison's full-sized avatar

David Robison drobison

View GitHub Profile
@drobison
drobison / gist:9139387
Created February 21, 2014 17:50
Common event handlers in JQuery
// Button Click
$("#btn").click(function(){
alert("Button Clicked");
});
// Drop Down List Change
$("#ddl").change(function () {
alert("Drop Down List Changed");
});
@drobison
drobison / gist:9125927
Created February 20, 2014 23:53
Syntax for executing a stored procedure in SQL Server
-- By Name
Exec StoredProcName
-- or simply
StoredProcName
-- With input variables
StoredProcName 'paramValue1', 'paramValue2', ...
-- With nameed input variables
@drobison
drobison / gist:9081905
Created February 18, 2014 22:38
Iterate through a DataTable in C#
DataTable dt = new DataTable();
// Populate said datatable
// ...
foreach(DataRow row in dt.Rows)
{
TextBox1.Text = row["Name"].ToString();
}
@drobison
drobison / gist:9076843
Created February 18, 2014 18:31
Set Drop Down List Selected Item by Value in C#
ListItem selectedListItem = DropDownList1.Items.FindByValue("Test");
if (selectedListItem != null)
{
selectedListItem.Selected = true;
}
@drobison
drobison / gist:9076817
Created February 18, 2014 18:29
Set Drop Down List Selected Item by Text in C#
ListItem selectedListItem = DropDownList1.Items.FindByText("Test");
if (selectedListItem != null)
{
selectedListItem.Selected = true;
}
@drobison
drobison / gist:9075218
Last active August 29, 2015 13:56
Bind a drop down list in ASP.NET with C# and ADO.NET
protected void StateDDL()
{
DataTable stateTable = new DataTable();
using (SqlConnection conn = new SqlConnection(ConnectionString))
{
SqlCommand sc_command = con.CreateCommand();
sc_command.CommandType = CommandType.Text;
sc_command.CommandText = @"Select State
, StateCode
from States
@drobison
drobison / gist:9074865
Last active August 29, 2015 13:56
Return single value in ADO.NET (C#)
protected int GetInt(string parameter)
{
string _con = ConfigurationManager.ConnectionStrings["SQLCON"].ConnectionString;
using (SqlConnection con = _con)
{
SqlCommand sc_command = con.CreateCommand();
sc_command.CommandText = "Select Age From Person where ID = @parameter";
sc_command.Parameters.AddWithValue("@parameter", parameter);
sc_command.CommandType = CommandType.Text;
@drobison
drobison / HasUniqueCharacters
Last active August 29, 2015 13:56
Determine if a string has all unique characters - (C#)
static void Main(string[] args)
{
Console.WriteLine("Hello");
Console.WriteLine(HasUniqueCharacters("Hello"));
Console.WriteLine("aAbBcCdDeEfFgG");
Console.WriteLine(HasUniqueCharacters("aAbBcCdDeEfFgG"));
Console.Read();
}
@drobison
drobison / SaveWindowPosition.js
Created May 6, 2013 16:04
#drobison #ASP.NET #JavaScript When using a custom validator in an update panel my window position was being lost. I was able to solve it with the following javascript.
window.scrollTo = function (x, y) {
return true;
}