Posts

Donate

Object doesn't support property or method call in consuming JSON object From ASP.NET MVC In Internet Explorer

Recently, I've followed a simple tutorial regarding consuming JSON object in ASP.NET MVC. The error stated from the title of this post appears in IE9. The original snippet is this: $(document).ready( $.getJSON( 'http://localhost:6222/home/customerjson' , function (item) { $( '#result' ) //show product name in .html( '<p>' + item.CurrentCustomer.CustomerName + '</p>' ); } ) ); The solution is to enclose $.getJSON() in a function() statement based from the modified code below. The popup script just went away. $(document).ready( function (){ $.getJSON( 'http://localhost:6222/home/customerjson' , function (item) { $( '#result' ) //show product name in .html( '<p>' + item.CurrentCustomer.CustomerName + '</p>' ); } ) ...

Eliminate Duplicate Rows In A DataTable In C#

Assuming you have a datatable that has merged contents from different datatables and you want to eliminate the datatable with distinct rows, you can use the statement below. dt.DefaultView.ToTable( true , new string [] { "id" , "name" }); Cheers!

Column 'column_name' Already Belongs To Another DataTable in C#

In a scenario where I added columns using AddRange(), I encountered an error as specified by the title. Here's the C# code: table1.Columns.AddRange( new DataColumn[] { col1, col2, col3 }); table2.Columns.AddRange( new DataColumn[] { col1, col2, col3 }); Where col1, col2, col3 are DataColumn objects. What I did was to initialize columns in the addrange method. But there are other solutions in the forums. table1.Columns.AddRange( new DataColumn[] { new DataColumn( "ID" ), new DataColumn( "WEB ID" ), new DataColumn( "URL" ) }); table2.Columns.AddRange( new DataColumn[] { new DataColumn( "ID" ), new DataColumn( "WEB ID" ), new DataColumn( "URL" ) });

WPF Datagrid (Prevent DataGrid Last Row From Being Sorted On Column Header Clicked)

Image
Here's the WPF version of prevent total rows from being sorted. Images: 1. Form Load, no column header is clicked (unsorted records) 2. Name header is clicked (sorting by column). The names are sorted alphabetically. Below are the methods used: /// <summary> /// column header clicked(sorting) /// </summary> private void dgProducts_Sorting( object sender, DataGridSortingEventArgs e) { DataRowView rv = (DataRowView)dgProducts.Items[dgProducts.Items.Count - 1]; if (rv[0].ToString().Contains( "Total:" )) { dvCopy = dgProducts.Items.SourceCollection as DataView; rv.Delete(); } sorted_aborted = e.Handled; } /// <summary> /// layout is updated /// </summary> private void dgProducts_LayoutUpdated( object sender, EventArgs e) { if (!sorted_aborted) { ...

Add Checkbox In WPF Datagrid DatagridTemplateColumnHeader (For Checkall)

Image
Hello, Here's how to add checkbox in WPF Datagrid DatagridTemplateColumn to simulate checkall. I have included the TSQL script, XAML and C# codes. Perform these steps below 1. Create an MSSQL database with the following Product Table schema below: Table: Products Fields: -    ProductID (int, autoincrement) -    ProductName (varchar) -    UnitPrice (decimal) -    QuantityPerUnit (varchar) -    Discontinue (bit)  SQL Script: USE [Your_Database_Name] GO /****** Object: Table [dbo].[Products] Script Date: 05/27/2013 14:07:39 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[Products]( [ProductID] [int] NOT NULL , [ProductName] [varchar](50) NULL , [UnitPrice] [decimal](18, 2) NULL , [QuantityPerUnit] [varchar](50) NULL , [Discontinue] [bit] NULL , CONSTRAINT [PK_Products] PRIMARY KEY ...

Prevent DataGridView Last Row From Being Sorted On Column Click

Image
Hello, You might have a row in the DataGridView typically the last one that computes total and the grid control is unbound to a datasource. And then if a sorting event occurs, you dont' wanna include that row during sort event. So given that your application has a form and a DataGridView control, the code to perform databinding is handled in the Form Load Event. DataGridViewRow dgRowTotalCount; DataTable dataTable; private void Form1_Load ( object sender, EventArgs e) { DataTable dt = new DataTable( "tblEntTable" ); dt.Columns.Add( "ID" , typeof ( string )); dt.Columns.Add( "Amount" , typeof ( decimal )); dt.Rows.Add( new object [] { "1" , 100.51 }); dt.Rows.Add( new object [] { "2" , 200.52 }); dt.Rows.Add( new object [] { "6" , 500.24 }); dt.Rows.Add( new object [] { "8" , 1000.11 }); dt.Rows.Add( new object [] { "4" , 400.31 }); dt.Rows.Add( new object [] { "5" , 6...

Regular Expression Word Boundary Not Working If Using A Variable In C#

In this scenario, I have to match an exact state abbreviation (QLD) that is Queensland. I declared an array containing state constant values. Normally this would work without using a string variable in C#: Regex.IsMatch(address, @"\bQLD\b" ) However, this won't work: if (Regex.IsMatch(address, @"\b" + str + "\b" )) The solution is to put an @ sign on both "\b" of the expression: string [] states = new string []{ "ACT" , "NSW" , "QLD" }; foreach ( string str in states) { if (Regex.IsMatch(address, @"\b" + str + @"\b" )) { state= str; address = address.Replace(str, "" ).Trim(); break ; } }

ASP.NET MVP Design Pattern (Simple)

Image
Out of boredom, I decided to read some ASP.NET Articles and came stumbling to Dino Esposito's MVP Flavors . After reading it, I decided to translate this into an ASP.NET application. I revised specifically the Presenter class since this has most of the interaction. Below are some snippets and screen shots: Image: 1. Solution Explorer for the Sample ASP.NET MVP Site 2. On Drop Down Selection of Customer 3. Button Expand Is Clicked, Show other records on other textbox controls. Presenter Class: public class Presenter { private IDefaultView view; public Presenter(IDefaultView viewObject) { view = viewObject; } public void InitializeView() { : view.AddCustomer( "Alfreds Futterkiste" , "ALFKI" ); view.AddCustomer( "Ana Trujillo Emparedados y helados" , "ANATR" ); view.AddCustomer( "Antonio Moreno Taquería" , "ANTON...

Convert Time From A Specific Timezone To Another Using CONVERT_TZ() In MySQL

In this scenario, we have to convert a timezone from Central USA to Hongkong time. I took note of DST here from (-06:00) to (-05:00). Here's a sample query. SELECT CONVERT_TZ( '2012-09-12 04:35:00' , '-05:00' , '+08:00' ) as convert_to_ph; Cheers!

Adding An Item to WPF Datagrid (C#)

Hello! VB.NET Version: Adding An Item to WPF Datagrid (VB.NET) Here's the C# version of how to add an item manually to a WPF DataGrid. DataGridTextColumn c1 = new DataGridTextColumn(); c1.Header = "Test" ; c1.Binding = new Binding( "test" ); c1.Width = 473; dataGrid.Columns.Add(c1); dataGrid.Items.Add( new Names() {test= "just testing" }); Class property: public string test { get ; set ; } XAML code: <DataGrid AutoGenerateColumns= "False" Height= "289" HorizontalAlignment= "Left" Margin= "10,10,0,0" Name= "dataGrid" VerticalAlignment= "Top" Width= "481" Grid.ColumnSpan= "2" ItemsSource= "{Binding }" > </DataGrid>

Donate