Sunday, February 5, 2012

In this post i am listing some GridView EditItemTemplate examples in Asp.Net 2.0,3.5 with Csharp and VB.NET.





Ajax autocomplete extender textbox in GridView

Example of Ajax Autocomplete Extender TextBox in EditItemTemplate of GridView.







Insert Update Edit Delete record in GridView

Insert Update Edit and Delete Records In GridView using ItemTemplate and EditItemTemplate.





Search records in GridView footer and highlight results using Ajax

Search records in GridView footer using footer template and ItemTemplate and highlight results using Ajax





Check All Checkbox In GridView To Bulk Edit Or Update

Implementing Check All CheckBox in ItemTemplate of GridView to perform Bulk Editing or Deleting









Hope This Helps
In this post i m showing some Ajax AutoComplete Extender Examples using ASP.NET C# and VB.NET with Database and WebService.




Ajax autocomplete extender textbox in GridView
In this example i am implementing the AutoComplete functionality to textbox in the EditItemTemaplate of GridView using AJAX autocomplete extender, for this we need to create a web service which calls the method to fetch data from database and display results as suggestions for textbox




AutoCompleteExtender TextBox CompletionList Width
Set Width of Completion List in Ajax AutoComplete Extender TextBox. The default behavior of completion list takes width equal to the width of textbox. we can change this behavior by applying some CSS style to set the width we want. default width is as shown below in the Image.


Ajax Autocomplete textbox add progress Image using javascript
add animated Progress Image inside Ajax Auto complete extender textbox to represent loading of data.






Winforms AutoComplete TextBox using C# in Windows application
In this example i am explaining how to create a AutoComplete TextBox In windows forms application using C#.lp



hope this helps
Add Expires Headers In Asp.NET

In this example i am Explaining how to add or set expires headers for static files or images in asp.net 2.0, 3.5

Performance is the main concern for any asp.net web application and bit of this can be achieved by setting expires headers for static files and images which doesn't change too often.


Add Expires Headers In asp.net 2.0 3.5


when expires headers are set for a future date or to never expires then browser fetch these files from cache and doesn't need to download these files every time application is loaded in browser, hence site or application is loaded faster




To do this we need to add code mentioned below in web.config file of asp.net web application

Set Expires headers to future date

<configuration>
    <system.webserver>
        <staticcontent>
            <clientcache cachecontrolcustom="" cachecontrolmode="UseExpires" httpexpires="Thu, 31 Dec 2020 00:00:00 GMT">
        </clientcache></staticcontent>
    </system.webserver>
</configuration>

Add headers to expire after certain days

<configuration>
  <system.webserver>
    <staticcontent>
      <clientcache cachecontrolmaxage="150.00:00:00" cachecontrolmode="UseMaxAge">
    </clientcache></staticcontent>
  </system.webserver>
</configuration>

Now the file headers will expire after 150 days


Hope this helps
Create setup Project In Visual Studio
Create Setup And Deployment Project in Visual Studio 2008/2010

In this example i am going to explain how to create setup and deployment project for winforms windows application using visual studio 2005/2008/2010.

Similar approach can be applied for creating setup project for web application as well.











First of all create any sample windows/web application.

Create setup project

right click on solution explorer root and select Add > New project 


In add new project dialog box select setup and deployment from other project types and then select Setup Project.


In the setup project file system editor window, right click on Application folder > Add > Project Output 


Now select primary output from next dialog box and click on OK.



Right click on User's desktop and create shortcut to primary output in application folder.


Similarly add shortcut in user's program menu.


Build the project by right clicking on setup project name and run the setup.


Hope this helps 

Maintain scroll position after postback
Maintain Scroll Position on or After Postback in Asp.Net 2.0 3.5.

In this example i'm explaining different methods of maintaining scroll position on/after postback in asp.net 2.0,3.5 web pages or applications.
















Method 1 .

Write below mention directive in page directive section of html source of aspx page to maintain scroll position of only one page or selected pages rather then whole web application.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"  
         MaintainScrollPositionOnPostback="true"  Inherits="_Default" %>



Method 2.

To maintain scroll position programmatically use code mentione below.
System.Web.UI.Page.MaintainScrollPositionOnPostBack = true;


Method3.

To maintain scroll position application wide or for all pages of web application we can write below mentioned code in pages section of web.config file so that we don't need to add page directive in each and every page.

<pages maintainScrollPositionOnPostBack="true">

Hope this helps.

Pass crystal report parameters programmatically in Asp.Net 2.0,3.5.

In this post i am explaining how to pass parameters to crystal reports programmatically in code behind of asp.net web page.

For this i am using northwind database and products table.

I have put one text box on the page and report will display details of product based on product id entered by user.




Read Crystal Reports In Asp.Net to know how to create crystal reports.

Read Crystal Reports With Parameters In WinForms Windows Forms to know how to create crystal reports with parameters in winforms or windows forms.

Open crystal report in design view, right click on it and select Field Explorer

Now select Parameter Fields and select new to add new parameter to report.

Name it as ProductID and remember it.

Now click on Special Fields in Field Explorer and select Record Selection Formula.

Select is equal to and {?ProductID} from the dropdowns and click on OK.

Click on smart tag of reportviewer control and uncheck Database logon prompting and parameter prompting as we will provide these info in code behind.


HTML markup of aspx page

<form id="form1" runat="server">
    <table class="style1">
        <tr>
            <td>
                Enter Product ID :
            </td>
            <td>
                <asp:TextBox ID="txtProductID" runat="server">
                </asp:TextBox>
                </td>
            <td>
                <asp:Button ID="btnReport" runat="server" 
                            Text="Show Report" 
                            onclick="btnReport_Click" 
                            Width="108px" />
                </td>
        </tr>
    </table>
    <br />
    <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" 
        AutoDataBind="True" EnableDatabaseLogonPrompt="False" 
        EnableParameterPrompt="False" Height="1039px" 
        ReportSourceID="CrystalReportSource1" 
        ReuseParameterValuesOnRefresh="True" 
        Width="901px" DisplayGroupTree="False" />
    <CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
        <Report FileName="CrystalReport.rpt">
        </Report>
    </CR:CrystalReportSource>
    </form>


Now go to code behind of the page and add below mentioned namespace for crystal reports.

1using CrystalDecisions.Shared;
2using CrystalDecisions.CrystalReports.Engine;

Write this code in Page_Load event of the page

1protected void Page_Load(object sender, EventArgs e)
2    {
3        if (Page.IsPostBack) CrystalReportViewer1.Visible = true;
4        else
5            CrystalReportViewer1.Visible = false;
6    }

Generate click event for button to shaow report and write this code.

01protected void btnReport_Click(object sender, EventArgs e)
02    {   //Create report document
03        ReportDocument crystalReport = new ReportDocument();
04 
05        //Load crystal report made in design view
06        crystalReport.Load(Server.MapPath("CrystalReport.rpt"));
07 
08        //Set DataBase Login Info
09        crystalReport.SetDatabaseLogon
10            ("amitjain", "password", @"AMITJAIN\SQL", "Northwind");
11 
12        //Provide parameter values
13        crystalReport.SetParameterValue("ProductID", txtProductID.Text);
14        CrystalReportViewer1.ReportSource = crystalReport;
15    }

Build the solution and run.


have fun.

Dynamic buttons controls Event Handling In windows forms or Winforms applications in .net 2.0,3,5. using C# and VB.NET

many times we need to create controls at runtime or through code behind depending on the real time scenario.

In this post i am going to explain how to add dynamic buttons at runtime and handle the Button Click event in winforms or windows forms applications.

I am creating 3 buttons on Form_Load event and placing them on the form.


Write this code in Load event of windows form.


C# Code

01private void Form1_Load(object sender, EventArgs e)
02        {
03            int x = 50, y = 50;
04            for (int i = 1; i <= 3; i++)
05            {
06                Button btnDynamic = new Button();
07                btnDynamic.Location = new System.Drawing.Point(x, y);
08                btnDynamic.Name = " Dynamic Button " + i;
09                btnDynamic.Size = new System.Drawing.Size(100, 50);
10                btnDynamic.Text = btnDynamic.Name;
11                Controls.Add(btnDynamic);
12                x += 100;
13                btnDynamic.Click += new EventHandler(this.DynamicButtonClick);
14            }
15 
16        }

Here x and y are horizontal and vertical cordinates where dynamically created buttons will be placed.

x is incremented by 100 each time so that buttons don't get placed overlapped.

when button is created, eventhandler for Click Event of button is associated with it in last line of above mentioned method.

Now write below mentioned method signature in the code behind

1private void DynamicButtonClick(object sender, EventArgs e)
2   {
3 
4   }

Method name must be exactly the same u mentioned in eventhandling code, as It's case sensitive. Write this code inside this method

1private void DynamicButtonClick(object sender, EventArgs e)
2        {
3            Button btnDynamic = (Button)sender;
4            btnDynamic.Text = "You Clicked" + btnDynamic.Name;
5 
6        }

VB.NET Code

01Private Sub Form1_Load(sender As Object, e As EventArgs)
02 Dim x As Integer = 50, y As Integer = 50
03 For i As Integer = 1 To 3
04  Dim btnDynamic As New Button()
05  btnDynamic.Location = New System.Drawing.Point(x, y)
06  btnDynamic.Name = " Dynamic Button " & i
07  btnDynamic.Size = New System.Drawing.Size(100, 50)
08  btnDynamic.Text = btnDynamic.Name
09  Controls.Add(btnDynamic)
10  x += 100
11  btnDynamic.Click += New EventHandler(AddressOf Me.DynamicButtonClick)
12 Next
13 
14End Sub
15 
16Private Sub DynamicButtonClick(sender As Object, e As EventArgs)
17 Dim btnDynamic As Button = DirectCast(sender, Button)
18 btnDynamic.Text = "You Clicked" + btnDynamic.Name
19 
20End Sub

Build the application and run.
Show or Hide Div using jquery

Show hide div using jquery example in asp.net.

So many times while developing web application we need to show or hide div or other html elements based on user interaction as shown in picture.

we can do this with ease using JQuery.








for this first of all we need to add jquery in head section of page.


1<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>

Now write some css for the div and show hide button

01.button, .button:visited {
02 background: #222;
03 display: inline-block;
04 padding: 5px 10px 6px;
05 color: #fff;
06 text-decoration: none;
07 -moz-border-radius: 6px;
08 -webkit-border-radius: 6px;
09 -moz-box-shadow: 0 1px 3px rgba(0,0,0,0.6);
10 -webkit-box-shadow: 0 1px 3px rgba(0,0,0,0.6);
11 text-shadow: 0 -1px 1px rgba(0,0,0,0.25);
12 border-bottom: 1px solid rgba(0,0,0,0.25);
13 font-size: 11px;font-weight: bold;line-height: 1;text-shadow: 0 -1px 1px rgba(0,0,0,0.25);
14        background-color: #2981e4;
15        top:250px;
16        float:left;
17        left:150px;
18        position:fixed;
19 
20}
21.button:hover {background-color: #2575cf;}
22 
23.detailDiv {
24 height:80px;
25        width: 400px;
26 background: #222;
27 display: inline-block;
28 padding: 50px 10px 6px;
29 color: #fff;
30 text-decoration: none;
31 -moz-border-radius: 6px;
32 -webkit-border-radius: 6px;
33 -moz-box-shadow: 0 1px 3px rgba(0,0,0,0.6);
34 -webkit-box-shadow: 0 1px 3px rgba(0,0,0,0.6);
35 text-shadow: 0 -1px 1px rgba(0,0,0,0.25);
36 border-bottom: 1px solid rgba(0,0,0,0.25);
37 position: relative;
38 cursor: pointer
39        font-size: 11px;font-weight: bold;line-height: 1;text-shadow: 0 -1px 1px rgba(0,0,0,0.25);
40        background-color: #91bd09;
41 text-align:center;
42}
43.detailDiv:hover {background-color: #749a02;}


Write this html code to hide or show the div
<div class="detailDiv">
This is example of Hide show div element using jquery 
</div>

<button class="button">Show or Hide div </button>

Now we will be showing or hiding the div on click of button so we need to add click event listener in jquery function as follows.

01<script type="text/javascript">
02 
03$(document).ready(function(){
04 
05        $(".detailDiv").hide();
06        $('.button').click(function(){
07 $(".detailDiv").slideToggle();
08 });
09 
10});
11 
12</script>

And result will be like one in demo below, Click on button to see it live.








Have fun with JQuery
Show or Hide Div using jquery

Show hide div using jquery example in asp.net.

So many times while developing web application we need to show or hide div or other html elements based on user interaction as shown in picture.

we can do this with ease using JQuery.








for this first of all we need to add jquery in head section of page.


1<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>

Now write some css for the div and show hide button

01.button, .button:visited {
02 background: #222;
03 display: inline-block;
04 padding: 5px 10px 6px;
05 color: #fff;
06 text-decoration: none;
07 -moz-border-radius: 6px;
08 -webkit-border-radius: 6px;
09 -moz-box-shadow: 0 1px 3px rgba(0,0,0,0.6);
10 -webkit-box-shadow: 0 1px 3px rgba(0,0,0,0.6);
11 text-shadow: 0 -1px 1px rgba(0,0,0,0.25);
12 border-bottom: 1px solid rgba(0,0,0,0.25);
13 font-size: 11px;font-weight: bold;line-height: 1;text-shadow: 0 -1px 1px rgba(0,0,0,0.25);
14        background-color: #2981e4;
15        top:250px;
16        float:left;
17        left:150px;
18        position:fixed;
19 
20}
21.button:hover {background-color: #2575cf;}
22 
23.detailDiv {
24 height:80px;
25        width: 400px;
26 background: #222;
27 display: inline-block;
28 padding: 50px 10px 6px;
29 color: #fff;
30 text-decoration: none;
31 -moz-border-radius: 6px;
32 -webkit-border-radius: 6px;
33 -moz-box-shadow: 0 1px 3px rgba(0,0,0,0.6);
34 -webkit-box-shadow: 0 1px 3px rgba(0,0,0,0.6);
35 text-shadow: 0 -1px 1px rgba(0,0,0,0.25);
36 border-bottom: 1px solid rgba(0,0,0,0.25);
37 position: relative;
38 cursor: pointer
39        font-size: 11px;font-weight: bold;line-height: 1;text-shadow: 0 -1px 1px rgba(0,0,0,0.25);
40        background-color: #91bd09;
41 text-align:center;
42}
43.detailDiv:hover {background-color: #749a02;}


Write this html code to hide or show the div
<div class="detailDiv">
This is example of Hide show div element using jquery 
</div>

<button class="button">Show or Hide div </button>

Now we will be showing or hiding the div on click of button so we need to add click event listener in jquery function as follows.

01<script type="text/javascript">
02 
03$(document).ready(function(){
04 
05        $(".detailDiv").hide();
06        $('.button').click(function(){
07 $(".detailDiv").slideToggle();
08 });
09 
10});
11 
12</script>

And result will be like one in demo below, Click on button to see it live.








Have fun with JQuery