Showing posts with label LINQ. Show all posts
Showing posts with label LINQ. 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.

Saturday, October 13

How to bind second Gridview with respect to first GridView

Introduction:-

                  Here I have explained RowEditing,RowUpdating,RowDeleting and RowCommand Events of gridview in asp.net.

Description:-


In previous post I have explained how to bind gridview by selecting a row from another gridview where data retrieves from database but in this example I will explain the same post with different approach without using database.
Here I have created two classes and using list collection binding two gridview.First it wil bind one gridview and by choosing any row data it will bind the another gridview having same record.

Here I am going to provide an example with source code, take a look. 

Thursday, October 4

Data Binding in DropDownList Using Jquery


Introduction:-

                     Here I have explained how to bind data in dropdownlist using jQuery.

Description:-

                  In my previous article I have explained How to calculate difference between two dates using JQuery? , How to get Checkboxlist valuewith comma Separator by jquery.


Here I will explain how to bind dropdownlist using jQuery.As you wnow it will be light weight than other processes.

 Here I am doing one simple web application for binding data to dropdownlist  through JQuery.

 For this first you have to add one web page name it as your choice,here I have named it as JqueryDropDownList.aspx

Tuesday, October 2

How to return List of Array


Introduction:-

                     Here I have explained how to return array list in webmethod.

Description:-


Here I am going to explain how return array list. If you are using Ajax method to bind a
dropdownlist or any grid controls, then you have to return some value from webmethod.  
Where as you must return a list value to your ajax success function to bind that control.

For this I am using here array list as return value.

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

Thursday, July 26

Join More Than Three Tables using Linq Query


//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Table1 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 
UHRMS_LeaveRequestApprovalObject objleave = new UHRMS_LeaveRequestApprovalObject();
List<UHRMS_LeaveRequestApprovalObject> LeaveDetails = new List<UHRMS_LeaveRequestApprovalObject>();
            if(Request.QueryString["LRID"]!=null)
            {
            objleave.Leave_Request_ID=Convert.ToInt32(Request.QueryString["LRID"].ToString());
            }
           
            LeaveDetails = UERPManagement.GetInstance.ShowLeaveApproveDetailsByID(objleave);
            int Employee_ID = 0;
            if (LeaveDetails.Count() != 0)
            {
            Employee_ID = Convert.ToInt32(LeaveDetails.ToList()[0].Employee_ID.ToString());
            }
  //@@@@@@@@@@@@@@@@@@@@@@@@ Table2 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
         

        List<UHRMS_EmployeePromotion> CurrentDetails = new List<UHRMS_EmployeePromotion>();
      CurrentDetails = UERPManagement.GetInstance.SelectEmploeePromotionDetails(Employee_ID);

           
            
  //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Table3 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

            List<UHRMS_LeaveAllocation> Leave = new List<UHRMS_LeaveAllocation>();
            Leave = UERPManagement.GetInstance.FillLeave();
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Table4 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 List<UHRMS_EmpContractRenewalDetails> EmpList = new List<UHRMS_EmpContractRenewalDetails>();
            EmpList = UERPManagement.GetInstance.GetEmployeeName(1);

//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@Joining 3 Tables@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


 var LeaveRecordsDetails = from mc in CurrentDetails
                               join y in LeaveDetails on mc.Employee_ID equals y.Employee_ID
                                   into grouping
                               from y in LeaveDetails
                               join o in Leave on y.Leave_Type_ID equals o.Leave_Type_ID
                               where y.Leave_Request_ID == Convert.ToInt32(Request.QueryString["LRID"].ToString())
                               select new { mc.Department_Name,y.Leave_Request_ID, mc.Designation_Name, y.Employee_ID, o.Leave_Type_Name, y.From_Date, y.To_Date, y.No_Of_Days, y.Leave_Status, y.Cause_Of_Leave };


//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@Joining above 3 Tables with 4th one @@@@@@@@@@@@@@@@@@

  var LeaveRecords = from a in LeaveRecordsDetails
                               join e in EmpList on a.Employee_ID equals e.EmployeeID
                               where a.Leave_Request_ID == Convert.ToInt32(Request.QueryString["LRID"].ToString())
                               select new { a.Department_Name, a.Designation_Name, a.Employee_ID,e.EmployeeName, a.Leave_Type_Name, a.From_Date, a.To_Date, a.No_Of_Days, a.Leave_Status, a.Cause_Of_Leave };
 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@Binding Data to fields @@@@@@@@@@@@@@@@@@
            if (LeaveRecords.Count() != 0)
            {
                txtDepartment.Text = LeaveRecords.ToList()[0].Department_Name;
                txtDesignation.Text = LeaveRecords.ToList()[0].Designation_Name;
                txtEmpName.Text = LeaveRecords.ToList()[0].EmployeeName;
                txtLeaveType.Text = LeaveRecords.ToList()[0].Leave_Type_Name;
                txtFromDate.Text = LeaveRecords.ToList()[0].From_Date.ToString("dd/MM/yyyy");
                txtToDate.Text = LeaveRecords.ToList()[0].To_Date.ToString("dd/MM/yyyy");
                txtNoOfDays.Text = LeaveRecords.ToList()[0].No_Of_Days.ToString();
                txtStatus.Text = LeaveRecords.ToList()[0].Leave_Status;
                txtCauseofLeave.Text = LeaveRecords.ToList()[0].Cause_Of_Leave;
            }


Thanks shibashish mohanty

.

ShibashishMnty
shibashish mohanty