2

AutoCompleteExtender Example Ajax




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


.

3

GridView EditItemTemplate Example





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


.

1

ObjectDataSource Examples With GridView In ASP.NET



Examples of ObjectDataSource With GridView in Asp.Net 2.0 and 3.5 with ObjectDataSource UpdateMethod, InsertMethod and Select Method  using C# csharp and VB.NET.

Here i have compiled list of few examples of GridView/DataList with ObjectDataSource i posted earlier in this blog.








Hide GridView Columns In ASP.NET







Display Images in Gridview/DataList using Objectdatasource






Insert Edit Update GridView with ObjectDataSource








Hope this helps

4

GridView Examples in ASP.NET 2.0 3.5








Here is the list of some Gridview examples in asp.net 2.0 and 3.5 using c# and vb.net.











Merge GridView Header Columns or multiple Headers




Search Records In GridView And Highlight Results Using AJAX




Export GridView To PDF In ASP.NET







Ajax ModalPop Extender In Master Detail Gridview





Export paging enabled GridView to pdf using iTextSharp





Delete Multiple Rows Or Records In Gridview With CheckBox Confirmation




LinkButton in GridView and QueryString





 Highlight GridView Row On MouseOver Using Javascript





AutoNumber Column or Auto Number in GridView or DataList




Edit Update Multiple Records/Rows In Gridview With Checkbox




Merge GridView Cells Or Columns in Row





Display Running Total In Gridview Footer in ASP.NET




Scrollable GridView with fixed headers





Display Images In GridView From DataBase




NULL In GridView EVAL Calling Serverside Method In ItemTemplate




Pass Send GridView Row Value/Data Using Hyperlink




Filtering GridView With Filter Expression And DropDownList









hope this helps



6

GridView Filter Expression with DropDownList ASP.NET

This example describes how to use GridView Filtering or Filter Gridview with DropDownList FilterExpression and filter paramaters in asp.net 2.0,3.5 with sql server 2008 and SqlDataSource.

I m using northwind database and customers table to show data and filter gridview with dropdownlist.

First of all open aspx page in design view and place 2 dropdownlist, 1 gridview and 3 SqlDatasource on the page.

Configure all 3 sqldatasources as according to code mentioned below. and use them for datasource to populate city dropdown, country dropdown and gridview.

You can also read ModalPopUp extender in Gridview to know how to configure SqlDataSource.

HTML Markup to Populate Dropdowns
<asp:DropDownList ID="ddlCity" runat="server" 
                  AppendDataBoundItems="True" 
                  AutoPostBack="True" 
                  DataSourceID="sqlDataSourceCity" 
                  DataTextField="City" 
                  DataValueField="City" Width="100px">
 <asp:ListItem Value="%">All</asp:ListItem>
 </asp:DropDownList>

<asp:SqlDataSource ID="sqlDataSourceCity" runat="server" 
ConnectionString="<%$ ConnectionStrings:northWindConnectionString %>" 
SelectCommand="SELECT DISTINCT City FROM Customers">
</asp:SqlDataSource>


<asp:DropDownList ID="ddlCountry" runat="server" 
                  AppendDataBoundItems="True" 
                  AutoPostBack="True" 
                  DataSourceID="sqlDataSourceCountry" 
                  DataTextField="Country" 
                  DataValueField="Country" Width="100px">
<asp:ListItem Value="%">All</asp:ListItem>
</asp:DropDownList>


<asp:SqlDataSource ID="sqlDataSourceCountry" runat="server" 
ConnectionString="<%$ ConnectionStrings:northWindConnectionString %>" 
SelectCommand="SELECT DISTINCT [Country] FROM [Customers]">
</asp:SqlDataSource>

Now Configure third sqldatasource to populate gridview based on filter expression as mentioned below

HTML markup of gridview and sqldatasource with filter expression
<asp:GridView ID="GridView1" runat="server" 
              AllowPaging="True" 
              DataSourceID="sqlDataSourceGridView" 
              AutoGenerateColumns="False"
              CssClass="GridViewStyle" 
              GridLines="None" Width="650px" 
              ShowHeader="false">
<Columns>
<asp:BoundField DataField="CustomerID" HeaderText="Customer ID"/>
<asp:BoundField DataField="CompanyName" HeaderText="Company"/>
<asp:BoundField DataField="ContactName" HeaderText="Name"/>
<asp:BoundField DataField="City" HeaderText="city"/>
<asp:BoundField DataField="Country" HeaderText="Country"/>
</Columns>
</asp:GridView>


<asp:SqlDataSource ID="sqlDataSourceGridView" 
                   runat="server" 
ConnectionString="<%$ ConnectionStrings:northWindConnectionString %>" 
SelectCommand="SELECT [CustomerID], [CompanyName], [ContactName], 
[City], [Country] FROM [Customers]" 
FilterExpression="[City] like '{0}%' and [Country] like '{1}%'">
<FilterParameters>
<asp:ControlParameter ControlID="ddlCity" Name="City" 
                      PropertyName="SelectedValue" 
                      Type="String" />
<asp:ControlParameter ControlID="ddlCountry" Name="Country" 
                      PropertyName="SelectedValue" 
                      Type="String" />
</FilterParameters>
</asp:SqlDataSource>

Build and run the application.

Download sample code attached




13

ModalPopUpExtender In Gridview


Ajax ModalPopUpExtender in master detail grdiview to open popup.

In this sample code example i am going to describe how to use Ajax ModalPopUp Extender in Gridview to display master detail or parent child data using sqlDataSource, AjaxControlToolkit,Sql Server 2008 and visual studio 2008.


I have used "Orders" and "Customers" table of Northwind database for this example.

Read install Northwind database on sql server 2008 to know how to install northwind or pubs sample database on sqlserver 2008.

Create new website in VS2008 and Create BIN folder by right clicking and selecting Add ASP.NET folder option in solution explorer.

Put AjaxControlToolkit.dll in this BIN folder and add reference to it.


open Default.aspx page source and register AjaxControlToolkit in page directive.
<%@ Register Assembly="AjaxControlToolkit" 
             Namespace="AjaxControlToolkit" 
             TagPrefix="AjaxToolkit" %>

Switch to design view and drag toolkitScriptManager on the page
Or add it in through page source.
<AjaxToolkit:ToolkitScriptManager ID="scriptManager" 
                                      runat="server">
    </AjaxToolkit:ToolkitScriptManager>

Drag and place an Update Panel on the page. we will put gridview and modal popup inside it in later part of this post
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
            </ContentTemplate>
</asp:UpdatePanel>

Now let's create SQLDataSource to populate the gridview and display orders table data.

switch to design view and drag sqldatasource control on the page and configure it according to pictures below.






<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
ConnectionString="<%$ ConnectionStrings:ModalPopUpConnectionString %>" 
SelectCommand="SELECT [OrderID], [CustomerID], [OrderDate], 
[ShippedDate], [ShipCity], [ShipCountry] FROM [Orders]">
</asp:SqlDataSource>


Now drag and place a GridView inside content template of Update panel and specify sqldatasource as datasource.

<asp:GridView ID="GridView1" runat="server" 
              AllowPaging="True" AutoGenerateColumns="False" 
              DataKeyNames="OrderID" 
              DataSourceID="SqlDataSource1" 
              CssClass="Gridview" 
              Width="650px" ShowHeader="false" PageSize="5">
<Columns>
<asp:BoundField DataField="OrderID" HeaderText="OrderID"/>
<asp:TemplateField HeaderText="CustomerID">
<ItemTemplate>
<asp:LinkButton runat="server" ID="lnkCustomer" 
                Text='<%#Eval("CustomerID") %>' 
                OnClick="lnkCustomer_Click">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="OrderDate" HeaderText="OrderDate"/>
<asp:BoundField DataField="ShippedDate" HeaderText="ShippedDate"/>
<asp:BoundField DataField="ShipCity" HeaderText="ShipCity"/>
<asp:BoundField DataField="ShipCountry" HeaderText="ShipCountry"/>
</Columns>
</asp:GridView>

Now add ModalPopUp extender and specify it's properties as mentioned below
<AjaxToolkit:ModalPopupExtender ID="modalPopUpExtender1" 
                           runat="server"
                           TargetControlID="btnModalPopUp"
                           PopupControlID="pnlPopUp"
                           BackgroundCssClass="modalBackground"
                           OkControlID="btnOk"
                           X="20"
                           Y="100">
</AjaxToolkit:ModalPopupExtender>

Now add one panel and one gridview inside this panel to display details
<asp:Panel runat="Server" ID="pnlPopUp" CssClass="confirm-dialog">
<asp:GridView ID="GridView2" runat="server" 
              CssClass="Gridview" Width="290px" 
              AutoGenerateColumns="false">
</asp:GridView>
</asp:UpdatePanel>

Complete HTML source of page will look like this
<form id="form1" runat="server">
    <div>
    
<AjaxToolkit:ToolkitScriptManager ID="scriptManager" 
                                  runat="server">

</AjaxToolkit:ToolkitScriptManager>
     
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
              AutoGenerateColumns="False" DataKeyNames="OrderID" 
              DataSourceID="SqlDataSource1" CssClass="Gridview" 
              Width="650px" ShowHeader="false" PageSize="5">
<Columns>
<asp:BoundField DataField="OrderID" HeaderText="OrderID"/>
<asp:TemplateField HeaderText="CustomerID">
<ItemTemplate>
<asp:LinkButton runat="server" ID="lnkCustomer" 
                Text='<%#Eval("CustomerID") %>' 
                OnClick="lnkCustomer_Click">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="OrderDate" HeaderText="OrderDate"/>
<asp:BoundField DataField="ShippedDate" HeaderText="ShippedDate"/>
<asp:BoundField DataField="ShipCity" HeaderText="ShipCity"/>
<asp:BoundField DataField="ShipCountry" HeaderText="ShipCountry"/>
</Columns>
</asp:GridView>

<asp:Button runat="server" ID="btnModalPopUp" 
            style="display:none"/>
            
<AjaxToolkit:ModalPopupExtender ID="modalPopUpExtender1" 
             runat="server"
             TargetControlID="btnModalPopUp"
             PopupControlID="pnlPopUp"
             BackgroundCssClass="modalBackground"
             OkControlID="btnOk"
             X="20"
             Y="100">
</AjaxToolkit:ModalPopupExtender>
                
<asp:Panel runat="Server" ID="pnlPopUp" CssClass="confirm-dialog">
<asp:GridView ID="GridView2" runat="server">
</asp:GridView>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
ConnectionString="<%$ ConnectionStrings:ModalPopUpConnectionString %>" 
SelectCommand="SELECT [OrderID], [CustomerID], [OrderDate], 
[ShippedDate], [ShipCity], [ShipCountry] FROM [Orders]">
</asp:SqlDataSource>
    
    </div>
    </form>

Write this code in click event of link Button in gridview to populate details or child gridview
protected void lnkCustomer_Click(object sender, EventArgs e)
    {
        //Retrieve Customer ID 
        LinkButton lnkCustomerID = sender as LinkButton;
        string strCustomerID = lnkCustomerID.Text;
        
        //Create sql connection and fetch data from database based on CustomerID
        string strConnectionString = ConfigurationManager.ConnectionStrings["ModalPopUpConnectionString"].ConnectionString;
        string strSelect = "SELECT CompanyName, ContactName, Address FROM Customers WHERE CustomerID = @customerID";
        SqlConnection sqlCon = new SqlConnection();
        sqlCon.ConnectionString = strConnectionString;
        SqlCommand cmdCustomerDetails = new SqlCommand();
        cmdCustomerDetails.Connection = sqlCon;
        cmdCustomerDetails.CommandType = System.Data.CommandType.Text;
        cmdCustomerDetails.CommandText = strSelect;
        cmdCustomerDetails.Parameters.AddWithValue("@customerID", strCustomerID);
        sqlCon.Open();

        //Create DataReader to read the record
        SqlDataReader dReader = cmdCustomerDetails.ExecuteReader();
        GridView2.DataSource = dReader;
        GridView2.DataBind();
        sqlCon.Close();
        modalPopUpExtender1.Show();
}


Download Sample Code




4

Install Northwind pubs database on sql server 2008

In this post i am going to describe how to install northwind or pubs sample database on sql server 2008.

Follow steps mentioned below

1. Download and install SQL2000SampleDb.msi from Microsoft Download center

It will be installed in "C:\SQL Server 2000 Sample Databases" folder.

Move Northwind and Pubs database files (MDF and LDF files) to your default database file location (C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data) from "C:\SQL Server 2000 Sample Databases" folder.

Now open sql server management studio and log in,
Right click on database > Select Attach > and locate the northwind.mdf file you just copied.






click on ok.

Install using scripts 

Open SQL Server Management Studio. Go to File >> Open >> Navigate to “C:\SQL Server 2000 Sample Databases\instpubs.sql”.





Select execute and this will install pubs database.



Popular Posts

Find More Articles