Check if value exists in array jquery - Solved

Introduction: In this tutorial, I am going to discuss about to check if the value exists in an array or not using jquery. The whole process done under the  <script></script> tag. Let's see. Check if the value already exists in array jquery 


Steps:
1. Make a function name like valexixts.
2. Declare an array[] of var type.
3. Add Jquery Library CDN link.

Coding Part:


<html>
<head>
    <title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
        function valexixts() {          
            var items = ['bat''ball''shirt''chair' 'fridge''tv'];
            var item = $('#txtItem').val();
if ($.inArray(item, items) != -1) 
            {
                $('#lblmsg').html(item + ' found');
            }
            else {               
                $('#lblmsg').html(item + ' not found');
            }
        }
    </script>
</head>
<body>
    <input type="text" id="txtcheck" />
       <button type="button" onclick="valexixts();">Check</button><br />
 <span id="lblmsg"></span>
</body>
</html>



Read More

[Solved] Jquery datepicker set value in textbox (Asp.net and Html Control)

Jquery date picker 

Today I going to show you how you set value in textbox using the Jquery date picker in asp.net or any other control (like HTML). Here we take a simple HTML textbox to pick a date using Jquery UI, in this process we use 3 ajax-official script link.Here we need to match the id of HTML Textbox $("#HTMLtxtbox").datepicker(); with the jquery id selector. If you want to implement date picker with asp.net textBox then try this $('#<%=ASPtxtbox.ClientID%>').datepicker();


Jquery datepicker set value textbox



<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <link rel="stylesheet" href="/resources/demos/style.css">
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <script>
        $(function () {

            //For HTML TextBOX
            $("#HTMLtxtbox").datepicker();
            $("#anim").on("change", function () {
                $("#HTMLtxtbox").datepicker("option", "showAnim", $(this).val());
            });


            //For Asp.Net TextBox
            $('#<%=ASPtxtbox.ClientID%>').datepicker();
            $("#anim").on("change", function () {
                $('#<%=ASPtxtbox.ClientID%>').datepicker("option", "showAnim", $(this).val());
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <table>
                <tr>
                    <td>Jquery DatePicker With Asp.net TextBox</td>
                    <td>
                        <asp:TextBox ID="ASPtxtbox" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>Jquery DatePicker With HTML TextBox</td>
                    <td>
                        <input type="text" id="HTMLtxtbox" />
                    </td>
                </tr>
            </table>
        </div>
    </form>

</body>
</html>


Read More

[Updated:2019] How to perform insert and update operation on single button

Save and update on the same button in asp net : 

Welcome Buddy, Today I am going to show you about "insert and update in one button c#". Actually, this is very simple to perform insert and update operation on single button, here is how you can do this. Just perform each and every step one by one.


"insert and update in one button c#"


Step #1:

Create store procedure for each insert,delete,update,edit


Create database Tutorial
use Tutorial


create table employee
(
eid int primary key identity,
ename varchar(50),
eadress varchar(50),
emob int
)


create proc employee_insert
@ename varchar(50),
@eadress varchar(50),
@emob int
as
begin
insert into employee(ename,eadress,emob)values(@ename,@eadress,@emob)
end

  
Create proc employee_grid
as
begin
select * from employee
end


Create proc employee_delete
@eid int
as
begin
delete  from employee where eid=@eid
select * from employee


Create proc employee_Edit
@eid int
as
begin
select * from employee where eid=@eid
end


Create proc employee_update
@eid int,
@ename varchar(50),
@eadress varchar(50),
@emob int
as
begin
   update employee set ename=@ename,eadress=@eadress,emob=@emob where eid=@eid
end


Step #2:



Add connectionstring in web.config file



<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5"/>
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <connectionStrings>
    <add name="DBCS" connectionString="initial catalog =Tutorial; data source=MYPC\SQL2012; integrated security=true"/>
  </connectionStrings>
</configuration>


Step #3:

Add one web form in your project with a respected name


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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <table>
                <tr>
                    <td>Name:</td>
                    <td>
                        <asp:TextBox ID="txtname" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>Address:
                    </td>
                    <td>
                        <asp:TextBox ID="txtaddress" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>Phone:</td>
                    <td>
                        <asp:TextBox ID="txtphone" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <asp:Button ID="btninsert" runat="server" Text="Insert" OnClick="btninsert_Click"></asp:Button>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <asp:GridView ID="grd" runat="server" AutoGenerateColumns="false" OnRowCommand="grd_RowCommand" >
                            <Columns>
                                <asp:TemplateField HeaderText="Name">

                                    <ItemTemplate>
                                        <%#Eval("ename") %>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Address">
                                    <ItemTemplate>
                                        <%#Eval("eadress") %>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Mobile">
                                    <ItemTemplate>
                                        <%#Eval("emob") %>
                                    </ItemTemplate>
                                </asp:TemplateField>

                                <asp:TemplateField>
                                    <ItemTemplate>
                                        <asp:LinkButton ID="lbn" runat="server" Text="Delete" CommandName="DLT" CommandArgument='<%#Eval("eid") %>'></asp:LinkButton>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField>
                                    <ItemTemplate>
                                        <asp:LinkButton ID="lbn1" runat="server" Text="Edit" CommandName="EDT" CommandArgument='<%#Eval("eid") %>'></asp:LinkButton>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>
                    </td>
                </tr>
            </table>
        </div>
    </form>
</body>
</html>


Step #4:

Come on .CS page and add necessary namespace

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;


public partial class _Default : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString);
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            grid_view();
        }
    }
    void OpenConnection()
    {
        if (con.State == ConnectionState.Closed)
            con.Open();
    }
    void CloseConnection()
    {
        if (con.State == ConnectionState.Open)
            con.Close();
    }
    public void grid_view()
    {
        OpenConnection();
        SqlCommand cmd = new SqlCommand("employee_grid", con);
        cmd.CommandType = CommandType.StoredProcedure;
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        if (ds.Tables[0].Rows.Count > 0)
        {
            grd.DataSource = ds;
            grd.DataBind();
        }
        CloseConnection();
    }
    protected void btninsert_Click(object sender, EventArgs e)
    {
        if (btninsert.Text == "Insert")
        {
            OpenConnection();
            SqlCommand cmd = new SqlCommand("employee_insert", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@ename", txtname.Text);
            cmd.Parameters.AddWithValue("@eadress", txtaddress.Text);
            cmd.Parameters.AddWithValue("@emob", txtphone.Text);
            cmd.ExecuteNonQuery();
            CloseConnection();
            grid_view();
        }
        else if (btninsert.Text == "Update")
        {
            OpenConnection();
            SqlCommand cmd = new SqlCommand("employee_update", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@eid", ViewState["abc"]);
            cmd.Parameters.AddWithValue("@ename", txtname.Text);
            cmd.Parameters.AddWithValue("@eadress", txtaddress.Text);
            cmd.Parameters.AddWithValue("@emob", txtphone.Text);
            cmd.ExecuteNonQuery();
            CloseConnection();
            grid_view();
        }
    }
    protected void grd_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "EDT")
        {
            OpenConnection();
            SqlCommand cmd = new SqlCommand("employee_Edit", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@eid", e.CommandArgument);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            CloseConnection();
            da.Fill(ds);
            if (ds.Tables[0].Rows.Count > 0)
            {
                txtname.Text = ds.Tables[0].Rows[0]["ename"].ToString();
                txtaddress.Text = ds.Tables[0].Rows[0]["eadress"].ToString();
                txtphone.Text = ds.Tables[0].Rows[0]["emob"].ToString();
            }
            grid_view();
        }
        else
        {
            OpenConnection();
            SqlCommand cmd = new SqlCommand("employee_delete", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@eid", e.CommandArgument);
            cmd.ExecuteNonQuery();
            CloseConnection();
            grid_view();
        }
        btninsert.Text = "Update";
        ViewState["abc"] = e.CommandArgument;
    }
}





Read More