Saturday, 26 July 2014

Nested gridview example Or Gridview inside gridview in Asp.net

How to execute a stored procedure with Parameters in C# program or How to call stored procedure with Parameters in in asp.net c# code

In this article I will explain How to execute a stored procedure with Parameters in C# program or How to call stored procedure with Parameters in in asp.net c# code.

In this session I will explain how establish a connection to sql server and How to execute stored procedure and How to declare sql command and how to fill sql data adapter code to dataset and How to pass parameters to Database.

Below namespaces are for establishing a connection to Sql server.

using System.Data.SqlClient;
using System.Data;

Below is the Database connection string

SqlConnection con = new SqlConnection("server=Localhost;database=DBName;uid=sa1;pwd=g@123;MultipleActiveResultSets=True");

// Use GetRole is a Stored Procedure name

SqlCommand cmd = new SqlCommand("GetRole", con);
cmd.CommandType = CommandType.StoredProcedure;

//Here we can add parameter
//Check syntax of the passing parameters

cmd.Parameters.Add(new SqlParameter("@UserID", txtUserID.Text));
cmd.Parameters.Add(new SqlParameter("@Password", txtPassword.Text));

// Use a SqlDataAdapter object to Execute the cmd

SqlDataAdapter daUserData = new SqlDataAdapter(cmd);

//Use a DataSet object to gather the returned rows and to work with these rows in addition to the return //values and the return parameters.

DataSet dsRole = new DataSet();
daUserData.Fill(dsRole);


Friday, 25 July 2014

How to execute a stored procedure within C# program or How to call stored procedure in asp.net c# code

In this article I will explain How to execute a stored procedure within C# program or How to call stored procedure in asp.net c# code In ASP.NET and C#.

In this session I will explain how establish a connection to sql server and How to execute stored procedure and How to declare sql command and how to fill sql data adapter code to dataset.

Below namespaces are for establishing a connection to Sql server.

using System.Data.SqlClient;
using System.Data;

Below is the Database connection string

SqlConnection con = new SqlConnection("server=Localhost;database=DBName;uid=sa1;pwd=g@123;MultipleActiveResultSets=True");

// Use GetRole is a Stored Procedure name

SqlCommand cmd = new SqlCommand("GetRole", con);
cmd.CommandType = CommandType.StoredProcedure;

// Use a SqlDataAdapter object to Execute the cmd

SqlDataAdapter daUserData = new SqlDataAdapter(cmd);

//Use a DataSet object to gather the returned rows and to work with these rows in addition to the return //values and the return parameters.

DataSet dsRole = new DataSet();
daUserData.Fill(dsRole);

Wednesday, 11 June 2014

How to convert a given word to pascal casing in ASP.NET ?

Today I am going to explain about how to convert a given word to pascal casing.

What is Pascal Casing?

The first letter in the identifier and the first letter of each subsequent concatenated word are capitalized.

For example

Sachin Tendulkar

In the above example we have capitalized the first characters in the both the words Sachin and Tendulkar.

At most times the user may not show interest in typing the first letter of his name in capital when he is entering his name in a text box. At that time we need a code in the backend which can automatically convert the text to capitals.

Take an asp textbox.

<asp:TextBox Id=”txtName” runat=”server”>

Call this textbox in the aspx.cs page.

Now write the following code in the aspx.cs page to convert the first letter each subsequent concatenated word to capitals.

System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(txtName.Text.ToLower());


This code automatically converts the starting letter of each word to capitals.

Wednesday, 16 April 2014

How to set focus on first or particular textbox during page load using JQuery in ASP.NET

In this article I will explain how to set focus on first or particular textbox during page load using JQuery in ASP.NET

In this scenario we need to write code for focus on first or particular textbox.

Example 1: Focus First Textbox

<script type="text/javascript">
$(document).ready(function () {
$('input:text:first').focus();
});
</script>

Example 2: Focus Particular Textbox

<script type="text/javascript">
$(document).ready(function () {
$(#txtFirstName').focus();
});
</script>

Below is the total code Textbox focus.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Set focus in particular textbox </title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>

// Focus first textbox

<script type="text/javascript">
$(document).ready(function () {
$('input:text:first').focus();
});
</script>

(Or)

// Focus Particular textbox

<script type="text/javascript">
$(document).ready(function () {
$(#txtFirstName').focus();
});
</script>

</head>
<body>
<form id="form1" runat="server">
<table align="Center">
<tr>
<td colspan="2">Set focus in particular textbox or First textbox
</td>
</tr>
<tr>
<td colspan="2" height="20px"></td>
</tr>
<tr>
<td>FirstName :</td>
<td>
<asp:TextBox runat="server" ID="txtFirstName" /></td>
</tr>
<tr>
<td>LastName :</td>
<td>
<asp:TextBox runat="server" ID="txtLastName" /></td>
</tr>
<tr>
<td>Location :</td>
<td>
<asp:TextBox runat="server" ID="txtLocation" /></td>
</tr>
<tr>
<td>City :</td>
<td>
<asp:TextBox runat="server" ID="txtCity" /></td>
</tr>
<tr>
<td>
<asp:Button runat="server" ID="btnSave" Text="Save" />
</td>
<td>
<asp:Button runat="server" ID="btnCancel" Text="Cancel" />
</td>
</tr>
</table>
</form>
</body>

</html>

Date picker (Or) Datepicker Examples