Posts

Showing posts with the label ASP.NET Web Forms

Donate

ASP.NET Web Forms GridView Show Confirm Dialog Using jQueryUI Dialog

Image
Good day! I've had some ASP.NET Webforms projects before that use the window confirm dialog box to prompt for alerts before doing any action in the page or control. Since I want these projects to be more interactive in nature, I decided to replace some of the confirm dialogs using jQueryUI. As of this time there are still tons of ASP.NET Webforms projects in maintenance mode. So it's safe to say that this technology will still be around for a couple of years. This tutorial does not use database but primarily focused on using the jQuery UI Dialog for ConfirmDelete action rather than using the traditional Window ConfirmDialog. To begin with, simply create an ASP.NET Webforms project with a Models folder. Inside that folder is a class that contains Contact information. [Serializable] public class Contact { public int ID { get ; set ; } public string Name { get ; set ; } public string Phone { get ; set ; } public string Address { get ; set ; } public strin

Bootstrap DatePicker Arrow Appears At The Bottom of Calendar

Image
Hi, I was asked by a developer on how to fix the arrow which appears at the bottom of the calendar dropdown and not below the textbox. This issue was raised in my previous post Bootstrap DatePicker Control in ASP.NET Webforms . The solution is to reference the bootstrap-datepicker.css instead of bootstrap-datepicker3.standalone.css <link rel= "stylesheet" href= "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.1/css/bootstrap-datepicker.css" /> <script type= "text/javascript" src= "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.min.js" ></script> <script type= "text/javascript" src= "Scripts/bootstrap.min.js" ></script> <script type= "text/javascript" src= "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.1/js/bootstrap-datepicker.min.js" ></script> <script type= "text/javascript" > Output

Repeater Web Server Control In ASP.NET Web Forms With Bootstrap And Entity Framework

Image
Happy New Year! This post will illustrate on how to apply Bootstrap styling to a Repeater control given that the template used will be a Table element. To begin with, create an ASP.NET WebForm project. This application will retrieve Employee information from Northwinds database. Add an ADO.NET Entity Framework 6.0 to your project which will hook up with the Employee table. Add a WebForm page to your solution then drag a Repeater control inside the div tag below the form tag. Make sure to reference the bootstrap file in your head tag. The Repeater control will utilize the table element as it's template for displaying employee information. For the record, the employee photo will be shown on the left column, while the personal details are presented on the right column. The table also made use of Bootstrap's table css classes. <head runat= "server" > <title></title> <link href= "Content/bootstrap.css" rel= "stylesheet&q

ASP.NET Web Forms GridView With Running Total Per Group Using JavaScript

Image
Basing from the post DataTable With Running Total Per Group which applies running total to a DataTable object, we can also achieve the same functionality through the front-end side by changing the structure of the GridView control given that this is an ASP.NET WebForm application. The snippet to set the control's data source is simple such as below: dt.Columns.AddRange( new DataColumn[ 5 ] { new DataColumn( "SrNo" , typeof ( int )), new DataColumn ( "PartyName" , typeof ( string )), new DataColumn ( "ItemName" , typeof ( string )), new DataColumn ( "ChqAmt" , typeof ( int )), new DataColumn ( "PartyCode" , typeof ( string ))}); dt.Rows.Add( 1 , "ABC Water Supply" , "Construction Service" , 400 , "ABC" ); dt.Rows.Add( 2 , "ABC Pump Services" , "Type 24 Engine Pump" , 150 , "ABC" ); dt.Rows.Add( 3 , "ABC Water Supply" , "12 Ft Wa

How To Compute DataTable With Running Total Per Group In C#

Image
Good Evening! There was a question raised by a developer if it's possible to compute the running total of a specific DataTable column per grouping or category. The solution is to mark the category as a flag variable that indicates the group to be calculated. The sample code below creates a DataTable object with fictitious information of hardware materials that belong to a particular group specifically PartyCode column. If a column belongs to that group, it will perform calculations. If not, reset the flag variable and total so as to perform new calculations. When computing totals for large number of records, make sure to sort the DataTable using it's category. DataTable dt = new DataTable(); dt.Columns.AddRange( new DataColumn[ 5 ] { new DataColumn( "SrNo" , typeof ( int )), new DataColumn ( "PartyName" , typeof ( string )), new DataColumn ( "ItemName" , typeof ( string )), new DataColumn ( "ChqAmt" , typeof ( int

Hide ASP.NET Web Forms GridView BoundField Column With Value Accessible Through JavaScript

To hide a BoundField column but make it's value still accessible through JavaScript just set column's ItemStyle-CssClass and HeaderStyle-CssClass properties using CSS class with value display:none . CSS .hiddenColumn { display : none ; } ASPX <asp:BoundField DataField= "GroupCode" HeaderText= "Group Code" ItemStyle-CssClass= "hiddenColumn" HeaderStyle-CssClass= "hiddenColumn" />

Export ASP.NET GridView To Excel And Preserve Leading Zeros

Image
Hi, There was a question raised on how to export data from ASP.NET Gridview to Microsoft Excel and preserve leading zeros of numeric values. A workaround that we have is to insert an   character before the cell value if that value starts with zero (0). So if the value starts with zero such as 0001, the result would be " 0001". Thus when exported to Excel, the leading zero is kept. cell.Text = string .Format( "&nbsp;{0}" , cell.Text); A suggested solution is to insert a Tab character ( ) but this fails on some occasions. After doing some research, replacing the tab character with &ensp; or &emsp; would also fix the issue. cell.Text = string .Format( "&ensp;{0}" , cell.Text); //or cell.Text = string .Format( "&emsp;{0}" , cell.Text); ASP.NET GridView Export Excel Report Cheers!

$.getJSON() Not Loading JSON File Within Visual Studio Project In ASP.NET Web Forms

Hi, I was trying to load a JSON file located within my Visual Studio project using $.getJSON(), however the code below doesn't work as expected. $.getJSON( '/Assets/misc/employee.json' , function (data) { alert( 'processing!' ); }) .done( function (r) { alert(r.message); }) .fail( function (s) { alert( 'oops the file is missing!' ); }); After investigating for a few hours, I tested the local path of the JSON file such as http://localhost:3766/Assets/misc/employee.json and the result was an exception " HTTP Error 404.3 - Not Found The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map. ". I remember the solution in one of my ASP.NET project was to set the MimeMap in the web.config inside the system.webServer element. After setting the MimeMap for json files, I can now load local JSON files using $.getJSON(). <system.web

How To Handle ASP.NET GridView TemplateFields Null Values In Aspx Markup

Hello, To handle null values in GridView TemplateFields through aspx/html markup rather than code-behind, you can simply use the language operators to those fields. One approach is to use the conditional ternary operator in C# and VB.NET. The sample codes below illustrates how to do in C# and VB.NET. For C#, use the (?) operator. While VB.NET uses If() operator. C#.NET Code <asp:TemplateField HeaderText= "Name" SortExpression= "EmpName" > <ItemTemplate> <asp:Label ID= "lbl" runat= "server" Text= '<%# Eval("EmpName") %>' ></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID= "txtEmployee" runat= "server" Text= '<%# Eval("EmpName") == System.DBNull.Value ? string.Empty : Eval("EmpName").ToString() %>' ></asp:TextBox> </EditItemTemplate> </asp:TemplateField> VB.NET Code <as

Using Dapper ORM in ASP.NET Web Forms (Visual Basic.NET)

Image
Hi, This is a conversion of this post Using Dapper ORM in ASP.NET WebForm to VB.NET language. Customer.vb Public Class Customer Public Property CustomerID() As Integer Get Return m_CustomerID End Get Set (value As Integer ) m_CustomerID = Value End Set End Property Private m_CustomerID As Integer Public Property CompanyName() As String Get Return m_CompanyName End Get Set (value As String ) m_CompanyName = Value End Set End Property Private m_CompanyName As String Public Property Address() As String Get Return m_Address End Get Set (value As String ) m_Address = Value End Set End Property Private m_Address As String Public Property City() As String Get Return m_City End Get Set (

Donate