Sunday, October 19, 2014

how to clear the dropdown check box and datepicker using javascript

clear section of dropdown( with and out check box inside) and datepicker -------------------------------------------------------------------------- function GetClearSelction() { $find('cbCustomer').clearSelection();--------> this for combo box var items = $find('cbCustomer').get_checkedItems(); var i = 0; while (i < items.length) {---> these five lines for combo box inside check box items[i].uncheck(); i++; } $find('cbZone').clearSelection(); this is for datepicker
------------------------ var fullDate = new Date() var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun","Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; var twoDigitMonth = ((fullDate.getMonth().length + 1) === 1) ? (fullDate.getMonth() + 1) : '0' + (fullDate.getMonth() + 1); var currentDate = fullDate.getDate() + " " + months[fullDate.getMonth()] + " " + fullDate.getFullYear(); document.getElementById("FrmDt_dateInput").value = currentDate; document.getElementById("ToDt_dateInput").value = currentDate; } this is button <input type="button" onclick="GetClearSelction();" value="Clear" />

Saturday, October 18, 2014

how to validate for 3 combo boxes using javascript

how to validate for 3 combo boxes using javascript
-----------------------------------------------------

<script type="text/javascript"> function onChange(obj) { var txtPRNO = document.getElementById("<%=txtPRNO.ClientID %>"); var cbAuth1 = document.getElementById('<%=cbAuthoriser1.ClientId%>'); var cbAuth2 = document.getElementById('<%=cbAuthoriser2.ClientId%>'); var cbAuth3 = document.getElementById('<%=cbAuthoriser3.ClientId%>'); if (obj == 1) { if (cbAuth1.value != "0") { if (cbAuth1.value == cbAuth2.value || cbAuth1.value == cbAuth3.value) { alert("Authoriser already selected. Plese selected another one. "); document.getElementById('<% =btndummy.ClientID %>').click(); cbAuth1.focus(); return false; } return false; } } if (obj == 2) { if (cbAuth2.value != "0") { if (cbAuth2.value == cbAuth1.value || cbAuth2.value == cbAuth3.value) { alert("Authoriser already selected. Plese selected another one. "); document.getElementById('<% =btndummy1.ClientID %>').click(); cbAuth2.focus(); return false; } return false; } } if (obj == 3) { if (cbAuth3.value != "0") { if (cbAuth3.value == cbAuth1.value || cbAuth3.value == cbAuth2.value) { alert("Authoriser already selected. Plese selected another one. "); document.getElementById('<% =btndummy2.ClientID %>').click(); cbAuth3.focus(); return false; } return false; } } return true; } </script>

Dispaly table records to gridview using c# .net

simple telerick grid and dispaly the database table values using c# .net
------------------------------------------------------------------------------------


simple 3 steps:

1)btnSave_Click 'button click
2)GetDataTable(parameter is query here)  ' calling function from grid
3)DataTable GetDataTable(string query)   ' defination of above function

or if you want to show the table separtely write code in view button.


step 1):
-------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;

namespace myFirstOfficeDemo
{
    public partial class alert : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {

            string str = "Data Source=.;Initial Catalog=alertDb;Integrated Security=True";
            SqlConnection con = new SqlConnection(str);
            con.Open();
            SqlCommand com = new SqlCommand("SP_ADD_ALERT", con);
            com.Parameters.Add("@header", SqlDbType.VarChar).Value = txtHeader.Text;
            com.Parameters.Add("@text", SqlDbType.VarChar).Value = txtText.Text;
            com.CommandType = CommandType.StoredProcedure;
            com.ExecuteNonQuery();
            string script = "alert('Saved');";
            ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", script, true);
            con.Close();
            txtHeader.Text = "";
            txtText.Text = "";
        }

        'protected void btnView_Click(object sender, EventArgs e)
        '{
        '  
        '}




step 2):
-------

       public void RadGrid1_NeedDataSource1(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            RadGrid1.DataSource = GetDataTable("SELECT alertId, header, text FROM utilAlert");
        }


step 3):
-------
        public DataTable GetDataTable(string query)
        {
            String ConnString = ConfigurationManager.ConnectionStrings["alertDbConnectionString"].ConnectionString;
            SqlDataAdapter adapter = new SqlDataAdapter();
            DataTable myDataTable = new DataTable();
            using (SqlConnection conn = new SqlConnection(ConnString))
            {
                adapter.SelectCommand = new SqlCommand(query, conn);
                adapter.Fill(myDataTable);
            }
            return myDataTable;
        }

     
    }
}