Friday, June 20, 2014

make checkbox checked in jquery on dropdown on change

 $("#ddlCladded").change(function () {
            var ddlCladdedval= parseInt($("#ddlCladded").val());
            if(ddlCladdedval==1){
                     $('#chkCladded').prop('checked',true);
            }
            else{
                     $('#chkCladded').prop('checked',false);
            }        
        });

dropdown on change event and current dropdown value

 $("#ddlCladded").change(function () {
            var ddlCladdedval= parseInt($("#ddlCladded").val());
         
        });

Thursday, June 19, 2014

check if string is empty in javascript

function isEmpty(str) {
            return (!str || 0 === str.length);
        }

check for nan javascript

The isNaN() function returns true if the value is NaN (Not-a-Number), and false if not.

var a = isNaN(123) + "<br>";
var b = isNaN(-1.23) + "<br>";
var c = isNaN(5-2) + "<br>";
var d = isNaN(0) + "<br>";
var e = isNaN("Hello") + "<br>";
var f = isNaN("2005/12/12") + "<br>";

false
false
false
false
true
true

how to remove read only attribute of textbox control through codebehind using asp.net

 txtusername.Attributes.Remove("readonly");

Wednesday, June 18, 2014

Get Data From datatable

DataTable dt = new DataTable();
            dt = _newleadspresenter.getAllLeaddata(LeadId);

string s = dt.rows[0].itemarray[0];

Read From Sqldatareader in asp.net

cmdstr = @"SELECT UserName, FirstName, MiddleName, LastName, Phone, Email, Profession, CategoryId, ReferredBy, LeadCategoryId, BirthDate, MaritalStatus, Note
                           FROM  Lead
                           WHERE (LeadId = " + LeadId + ")";
                myConnection.Open();
                SqlCommand cmd = new SqlCommand(cmdstr, myConnection);
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {

                    txtusername.Text = reader.GetString(0);                  

                    txtfirstname.Text = reader.GetString(1);

                    txtmiddlename.Text = reader.GetString(2);

                    txtlastname.Text = reader.GetString(3);

                    txtphone.Text = reader.GetString(4);

                    txtemail.Text = reader.GetString(5);

                    txtprofession.Text = reader.GetString(6);

                    ddlcategory.SelectedValue = reader.GetString(7);

                    ddlstatus.SelectedValue = reader.GetString(9);

                    txtbirthdate.Text = reader.GetString(10);

                    ddlmaritalstatus.SelectedValue = reader.GetString(11);

                    txtnote.Text = reader.GetString(12);

                }

                myConnection.Close();

            }