Posts

Donate

ASP.NET Gridview Not Getting New Values In RowUpdating() Event

Assuming in your row updating event, you do some editing in your textbox and then click update button. The event in turn saves your modified records to the database. However, when you tried rebinding the datasource of Gridview it seems that you didn't get the newly updated values. The simple trick would be to set the Gridview property EnableViewState to false .

Get Current ID In Task Object (C#)

Doing some research on Task (TPL) i wonder if there's a way in retrieving the id of the current task executing. In thread, we can do it like this: Thread.CurrentThread.Name; The equivalent code in task is shown below: int currentTask = Task.CurrentId; Greg

Pivot Or Crosstab SQL Query Example

Image
Based from Visual Basic Forums, I learned a tip on using Crosstab/Pivot queries. This is presented with SQL Server Execution Plan. It's better to use the concept of the second one compared with the first one. SELECT SUM ( CASE WHEN DATEDIFF( DAY , upload_package_received_date, GETDATE()) = 0 THEN 1 ELSE 0 END ) AS Today, SUM ( CASE WHEN DATEDIFF( DAY , upload_package_received_date, GETDATE()) <= 7 THEN 1 ELSE 0 END ) AS Last_Week, SUM ( CASE WHEN DATEDIFF( DAY , upload_package_received_date, GETDATE()) <= 30 THEN 1 ELSE 0 END ) AS [30 Days Ago] FROM temp_uploadpackage Second Example SELECT ( SELECT COUNT (1) FROM temp_uploadpackage WHERE DATEDIFF( DAY , upload_package_received_date, GETDATE()) = 0) AS Today, ( SELECT COUNT (1) FROM temp_uploadpackage WHERE DATEDIFF( DAY , upload_package_received_date, GETDATE()) <= 7) AS Last_Week, ( SELECT COUNT (1) FROM temp_uploadpackage WHERE DATEDIFF...

How To Reference System.Web.Mvc In Class Library (ASP.NET MVC)

If your going to add reference to System.Web.Mvc in your class library, simply locate the assembly in Microsoft ASP.NET folder in program files. Using search in windows explorer in my workstation, the assemblies are located here: C:\Program Files\Microsoft ASP.NET\ASP.NET MVC (version_number)\Assemblies Greg

DataGridview Current Row Returns Null In SelectionChanged Event

When retrieving selected row cell values in the DataGridview, you might encounter object not set to reference of an instance. It's because the current row has not been initialized. Check first the cell value of the current row if it has cell contents. private void dgvAccounts_SelectionChanged( object sender, EventArgs e) { string countryName = string .Empty; if (dgvAccounts.SelectedRows.Count > 0) { if (dgvAccounts.CurrentRow.Cells[1].Value != null ) { countryName = dgvAccounts.CurrentRow.Cells[1].Value.ToString(); } } } This will ensure that databinding has finished. Cheers!

A field or property with the name 'ClassName.Property' was not found on the selected data source In ASP.NET Gridview

As i was running an asp.net application in my local machine, I encountered an exception which is the title of this post. This asp.net app runs perfectly from the other workstation. I tried searching solutions in google but found out that most of the recommendations were to redo the model or the business tier. One option I tried was to replace the BoundField of the gridview with TemplateField with label as the bound control using Eval("expression"). Glad that worked. It could be an IIS issue as stated in other forums. Here's the gridview markup changes: (Windows 7 64 Bit using BoundField) <asp:BoundField DataField= "Product.Name" HeaderText= "Name" > <ItemStyle Width= "350px" /> </asp:BoundField> (Windows 7 32 Bit using TemplateField) <asp:TemplateField HeaderText= "Product Name" > <ItemStyle Width= "350px" /> <ItemTemplate> <asp:Label ID= ...

Using AutoMapper In Asp.Net Web Forms Database Application

Image
Hello, Based from Scott Millet's Asp.Net Design Patterns , I was curious on the AutoMapper Framework that maps Domain Entities to View Models. So I tried to give it a spin by incorporating the tool in an ASP.NET WebForms application. Here's the code snippets breakdown: Order class: /// <summary> /// One order may contain one or many order details. /// </summary> public class Order { public int OrderId { get ; set ; } public DateTime OrderDate { get ; set ; } public DateTime RequiredDate { get ; set ; } public string ShipName { get ; set ; } public string ShipAddress { get ; set ; } public IList<OrderDetails> OrderDetail { get ; set ; } } Order View class: public class OrderView { public int OrderId { get ; set ; } public DateTime OrderDate { get ; set ; } public DateTime RequiredDate { get ; set ; } public string ShipName { get ; set ;...

WPF Datagrid Paging In VB.NET Using CollectionView Class

Image
Based from the solution posted by timmyl here: How can I paginate a WPF DataGrid? . I managed to fix some bugs and added some functionalites such as MoveToFirstPage and MoveToLastPage. Paging Class 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 Option Infer On Imports System.Collections Imports System.Collections.Generic Imports System.ComponentModel Imports System.Windows.Data Public Class PageCollectionView Inherits CollectionView Private ReadOnly _innerList As IList Private ReadOnly _itemsPerPage As Integer Private _currentPage As...

DataGridview Paging Using BindingSource And BindingNavigator In VB.NET

Image
Hi, In reference to the previous post on DataGridView paging using C# Datagridview paging using BindingSource in C# , I developed a Visual Basic.NET version for VB.NET Developers. Main Form Class: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 Option Infer On Imports System.Configuration Imports System.ComponentModel Imports MySql Imports MySql.Data Imports MySql.Data.MySqlClient Public Class FBinding Public Property TotalRecords() As Integer Public Const PageSize = 10 Private sourceData As New List( Of String ) Private dtSource As New DataTable Dim page As New PageOffsetList() Public Sub New() ' This call is required by the designer. InitializeComponent() ' Add any initiali...

DataGridview Paging Using BindingSource And BindingNavigator In C#

Image
Hello, VB.NET Version Here: DataGridview Paging Using BindingSource And BindingNavigator In VB.NET Here's a simple way to integrate paging in Datagridview using BindingNavigator and BindingSource. The original source can be found here: How can we do paging in datagridview in winform . I made some modifications to simulate loading of thousands of records from a database. Main Form Class: public partial class FBinding : Form { public static int totalRecords { get ; set ; } public const int pageSize = 10; private List< string > sourceData = new List< string >(); private DataTable dtSource = new DataTable(); public FBinding() { InitializeComponent(); bindingNav.BindingSource = bindingWebsite; bindingWebsite.CurrentChanged += new EventHandler(bindingWebsite_CurrentChanged); SetSource(); bindingWebsite.DataSource = new PageOffsetList(); } void bindingWebsite_CurrentChanged( object sender, EventAr...

Donate