Display Images in RadioButtonList Control in ASP.NET

October 20, 2016 Leave a comment

Hi all,

Try this example to Display Images in RadioButtonList Control in ASP.NET

You can also check my previous posts

Bind RadioButtonList with Image from Database

Bind RadioButtonList to Image

Step 1: Create a new ASP.NET Web Application in Visual Studio. Add a folder in the root named Images. Right-click on the project name and select:

Add -> New Folder

Now add some images in this folder to show with RadioButtons in the RadioButtonList control. Right-click on the Images folder and select:

Add -> Existing Item


Step 2: Add a RadioButtonList in HTML source view of Default.aspx, as shown in the following:

<asp:RadioButtonList ID="RadioButtonList1" runat="server"
BorderStyle="Groove" BorderWidth="1px" RepeatColumns="3" RepeatLayout="Table">

RepeatColumns of RadioButtonList is set to “3” to divide its items in three columns. For example if we have 18 items in the RadioButtonList, it will be displayed in 3 columns with 6 RadioButtons in each column.
The RepeatLayout property is used to specify the arrangement of RadioButtons inside the RadioButtonList control. By default or when it is set to “Table”, RadioButtons are rendered in a table but if it is set to “Flow”, it is rendered without a table.

Step 3: Write the following code in the Page Load event of Default.aspx.cs:

protected void Page_Load(object sender, EventArgs e)
ListItem item;
int i = 0;
System.IO.FileInfo file;

var Images =
from n in System.IO.Directory.GetFiles(Server.MapPath("Images"))
orderby n descending
select n;

foreach (var filename in Images)
file = new System.IO.FileInfo(filename);

item = new ListItem("<img src='" + "Images/" + file.Name + "' alt='" + file.Name +
"' title='"+file.Name+"'/>", i.ToString());

RadioButtonList1.CellPadding = 5;
RadioButtonList1.CellSpacing = 5;

Hope this helps

Good Luck.


Categories: ASP.Net

Convert Number to Word In SQL Sever

September 20, 2016 Leave a comment

Hi all,

Try this example to convert number to word in SQL Server

Create FUNCTION [dbo].[NumberToWords]
@Amount bigint
RETURNS nvarchar(max)
declare @Ones table (Id int, Name nvarchar(50))
declare @Decades table (Id int, Name nvarchar(50))
insert into @Ones(Id,Name) values(0,''),(1,'One'),
insert into @Decades(Id,Name) values(20,'Twenty'),(30,'Thirty'),
declare @str nvarchar(max)
set @str=''

if(@Amount >= 1 AND @Amount <20)
set @str=@str+ (select Name from @Ones where Id=@Amount)

if(@Amount >= 20 AND @Amount <=99)
set @str=@str+ (select Name From @Decades where Id=
(@Amount- @Amount%10))+' ' +(select Name From @Ones where Id=(@Amount%10)) +' '

if(@Amount >= 100 AND @Amount <=999)
set @str=@str+ dbo.NumberToWords(@Amount/100) +'
Hundred '+dbo.NumberToWords(@Amount%100)

if(@Amount >= 1000 AND @Amount <=99999)
set @str=@str+ dbo.NumberToWords(@Amount/1000) +'
Thousand '+dbo.NumberToWords(@Amount%1000)

if(@Amount >= 100000 AND @Amount <=9999999)
set @str=@str+ dbo.NumberToWords(@Amount/100000) +'
Lac '+dbo.NumberToWords(@Amount%100000)

if(@Amount >= 10000000 )
set @str=@str+ dbo.NumberToWords(@Amount/10000000) +'
Crore '+dbo.NumberToWords(@Amount%10000000)

return @str

Hope this helps

Good Luck.

Categories: SQL Server

List the Name of the Months Between Date Ranges in SQL Server

August 29, 2016 Leave a comment

Hi all,

Try this example to List the Name of the Months Between Date Ranges in SQL Server

DECLARE @sDate DATETIME = '20160301', @eDate DATETIME = '20160901';

;WITH cte AS
SELECT @sDate AS dates
SELECT DATEADD(mm,1,c.dates)
FROM cte c
WHERE c.dates < @eDate
FROM cte

Hope this helps

Good Luck.

Categories: SQL Server

Allow User to Enter Arabic Characters Or Number Only

July 24, 2016 Leave a comment

Dear all,

Try this example to Validate User to enter Arabic characters or numbers only

<asp:TextBox ID="txt_Name" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="rev_Name" runat="server" ErrorMessage="*" ControlToValidate="txt_Name" ValidationExpression="^[0-9\u0600-\u06FF/ ]+$" ></asp:RegularExpressionValidator>

Hope this helps

Good Luck.

Categories: ASP.Net

Set Maximum characters to 1000 for Multiline TextBox Using JQuery

July 22, 2016 Leave a comment

Hi all,

Try this example to Set Maximum characters to 1000 for Multiline TextBox Using JQuery

<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
 <script type="text/javascript">
 $(document).ready(function () {
 //Assign the text to span in pageload
 $('#spntxtMult').text("Number of characters 0/1000");
 //attach change event to div
 $('#txtMult').keyup(function (event) {
 //call function to calcualate count on change event of div
 function textCounter() {
 //Get the max length countnt
 var divlength = $('#txtMult').val().length;
 //check if count greater than 1000
 if (divlength > 1000) {
 //Trim the text
 var trimmedtext = $('#txtMult').val().substring(0, 1000);
 //assign it to textbox
 else {
 var remaningchar = 0;
 //Calculate the remining char
 if (divlength > 0) {
 remaningchar = 1000 - divlength;

//reduce the allowed no of characters in span
 $('#spntxtMult').text("Number of characters " + remaningchar + "/1000");
<asp:TextBox ID="txtMult" runat="Server" TextMode="MultiLine" />
<span id="spntxtMult"></span>

Hope this helps

Good Luck.

Categories: ASP.Net, Javascript, Jquery

Debug ASP.NET Web Application hosted in IIS using Visual Studio

Hi all,

Try this example to Debug ASP.NET Web Application hosted in IIS using Visual Studio

1. Click the Tools menu in Visual Studio and click the item Attach Process.


2. Search through the Available Processes with the name w3wp.exe.


3. Click the Attach button. Now you can watch your break point while doing relevant action in web page

Hope this helps

Good Luck

Categories: ASP.Net

Create An Error Log File

Hi all,

Try this example to Create an error log file

Step 1: Add a Global.asax file to Project/website if not exist.

Step 2: Now add the namespace to Global.asax file.

<%@ Import Namespace="System.IO" %>

Step 3: After that write the below given code in Application_Error event of Global file:

void Application_Error(object sender, EventArgs e)
// Code that runs when an unhandled error occurs
Exception ex = new Exception();
ex = Server.GetLastError().GetBaseException();
FileStream fs = new FileStream(Server.MapPath("~/ErrorLOG.txt"), FileMode.OpenOrCreate, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs);
sw.BaseStream.Seek(0, System.IO.SeekOrigin.End);
sw.WriteLine("ERROR DATE: " + System.DateTime.Now.ToString(System.Globalization.CultureInfo.InvariantCulture));
sw.Write("ERROR MESSAGE: " + ex.Message);
sw.Write("SOURCE: " + ex.Source);
sw.Write("FORM NAME: " + System.Web.HttpContext.Current.Request.Url.ToString());
sw.Write("QUERYSTRING: " + Request.QueryString.ToString());
sw.Write("TARGETSITE: " + ex.TargetSite.ToString());
sw.Write("STACKTRACE: " + ex.StackTrace + System.Diagnostics.EventLogEntryType.Error);

Hope this helps

Good Luck.

Categories: ASP.Net