Showing posts with label Linq to sql. Show all posts
Showing posts with label Linq to sql. Show all posts

Saturday, March 23

How to retrieve data using linq query in DataTable

Introduction:-
                     Here I have explained How to retrieve data using linq query stored in DataTable in asp.net.
Description:-
In this Article I will explain how to store data into datatable using linq query in asp.net.I have used here data context class and by creating the object of that class we can get the tables present inside that object.

Sunday, September 30

Collapsible Gridview using jquery


Introduction:-
               
                Here I have explained how to create a collapsible gridview having child gridview     control inside it using jquery.
Description:-                
              
                    In this article I will explain how to create a gridview having colapsable functionality using jquery.

Sometimes we are showing all records in a form which is not looks better in design prosperous. To overcome it we have to collapse these records until a user will not expand it.

I am going to explain the entire process step by steps.

I have used checkbox for collapse or expand. If you will checked it ,It will expand and will show you the hidden data or controls inside that and if you unchecked then it will collapse as usual.

Here I am creating a simple web application of  collapsible Gridview .I have taken two gridview control ,the parent gridview  showing data of Employee and the child gridview populating some fields for providing feedback against each employee.

Thursday, August 9

Download Source Code AutoComplete TextBox Using Webservice Application

I am shibashish mohanty going to show you a simple Auto complete Application using web services.

Dopwnload Source Code From My Code Project Article

My source Code:-


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TextBoxAutoComplete.aspx.cs" Inherits="Test.LINQInsert" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function setCompanyMasterID(source, eventargs) {
            document.getElementById("Label2.ClientID").value =
                                         eventargs.get_value();
            document.getElementById("Label2.ClientID").value =
       document.getElementById("TextBox1.ClientID").value;
        }
</script>
    </head>
<body>
  
    <form id="form1" runat="server">
<asp:ScriptManager runat="server"></asp:ScriptManager>
   
   
    <table >
        <tr>
            <td  >
                ID</td>
            <td>
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
   
   
            </td>
        </tr>
        <tr>
            <td>
                Name</td>
            <td>
                <asp:TextBox ID="TextBox4" runat="server" AutoPostBack="True"
                    ontextchanged="TextBox4_TextChanged"></asp:TextBox>
                <asp:AutoCompleteExtender ID="TextBox4_AutoCompleteExtender" runat="server"
                    DelimiterCharacters=""
                Enabled="True" MinimumPrefixLength="1"  ServicePath="Service1.svc" ServiceMethod="TXTSEARCH" TargetControlID="TextBox4"></asp:AutoCompleteExtender>
            </td>
            <td>
                &nbsp;</td>
        </tr>
    </table>
    <p>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
            DataSourceID="SqlDataSource1">
            <Columns>
                <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
                    ReadOnly="True" SortExpression="ID" />
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
            ConnectionString="<%$ ConnectionStrings:TestConnectionString2 %>"
            SelectCommand="SELECT * FROM [TextboxAutoImpliment]"></asp:SqlDataSource>
    </p>
    <p>

     <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"
                   ></asp:TextBox>
                <asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
                    DelimiterCharacters=""
                Enabled="True" MinimumPrefixLength="1"  ServicePath="Service1.svc" ServiceMethod="GetCountries" OnClientItemSelected="setCompanyMasterID" TargetControlID="TextBox1"></asp:AutoCompleteExtender>
          
        <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
        <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
          
       </p>
    </form>
</body>
</html>


My Code Behind:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Threading;
namespace Test
{
    public partial class LINQInsert : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
          
        }

        protected void TextBox4_TextChanged(object sender, EventArgs e)
        {
            DataClasses1DataContext d1 = new DataClasses1DataContext();
            var res = (from result in d1.TextboxAutoImpliments
                       where result.Name.ToLower().StartsWith(TextBox4.Text.ToLower())

                       select new { ID = result.ID }).Take(10);
            foreach (var id in res)
            {
                Label1.Text = id.ToString();
            }
        }

      
       
    }
}

My webService Method:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Configuration;
using System.Data.SqlClient;
using AjaxControlToolkit;

namespace Test
{
    /// <summary>
    /// Summary description for AutoComplete
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
    // [System.Web.Script.Services.ScriptService]
    public class AutoComplete : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [System.Web.Services.WebMethod]

        public static string[] GetSuggestions(string prefixText, int count)
        {

            try
            {



                string conStr;

                conStr = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

                string sqlQuery = "SELECT [Name],[ID] FROM [TextboxAutoImpliment] WHERE Name like @Name";



                SqlConnection conn = new SqlConnection(conStr);

                SqlCommand cmd = new SqlCommand(sqlQuery, conn);

                cmd.Parameters.AddWithValue("@Name", prefixText + "%");

                conn.Open();



                SqlDataReader dr = cmd.ExecuteReader();

                List<string> custList = new List<string>();

                string custItem = string.Empty;



                while (dr.Read())
                {

                    custItem = AutoCompleteExtender.CreateAutoCompleteItem(dr[0].ToString(), dr[1].ToString());

                    custList.Add(custItem);

                }



                conn.Close();

                dr.Close();



                return custList.ToArray();



            }

            catch (Exception ex)
            {

                throw ex;

            }

        }

    }
}
My database Look:-

Aftter Running View:-


Dopwnload Source Code From My Code Project Article

 Thanks Shibashish Mohanty

.

ShibashishMnty
shibashish mohanty