add

Monday, 29 July 2013

Delete Multiple Records From Gridview and also asking Permission to whether the record is delete or not

First Add this script to header tag on .aspx page:

  <script type="text/javascript" language="javascript">
        function DeleteConfirmation() {
            if (confirm("Are you sure, you want to delete selected records ?") == true)
                return true;
            else
                return false;
        }
    </script>


and call this function on button like this:

OnClientClick="return DeleteConfirmation()"

First Get the records from database attache to gridview

write the following code on button click event:

 string strID = string.Empty;

        for (int i = 0; i < gvsample.Rows.Count; i++)
        {
            CheckBox chkDelete = (CheckBox)gvsample.Rows[i].
                             Cells[0].FindControl("chkSelect");
            if (chkDelete != null)
            {
                if (chkDelete.Checked)
                {

                    Label lbldeleteid = (Label)gvsample.Rows[i].Cells[1].FindControl("lblid");
                    if (strID != string.Empty)
                        strID += ",";
                    strID += "" + lbldeleteid.Text + "";
                    //strID  = lbldeleteid.Text;
                    //idCollection.Add(strID);
                }
            }
        }
        string s1 = "delete from store where id in("+strID+")";
        //sb += sb.AppendFormat("{0}='{1}'; ", s1, item);
        con.Open();
        SqlCommand cmd = new SqlCommand(s1, con);
        //cmd.ExecuteNonQuery();
        int j = Convert.ToInt32(cmd.ExecuteNonQuery());
        con.Close();
        if (j > 0)
        {
            lblsample.Text = j+"Record(s) Deleted Sucessfully";
        }
        else
        {
        }
        getdata();

Sending E-Mail With Attachment

 MailMessage mail = new MailMessage();
         mail.To.Add("To mail id");
     
        mail.From = new MailAddress("From mail id");
        mail.Subject = "mail";
        mail.Body = "find the attached file";
        mail.IsBodyHtml = true;

      //Attach file using FileUpload Control and put the file in memory stream

        mail.Attachments.Add(new Attachment("Attached document file path"));
     
      SmtpClient smtp = new SmtpClient();
       smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
       smtp.Credentials = new System.Net.NetworkCredential
           ("u r email id", "password");
       //Or your Smtp Email ID and Password
       smtp.EnableSsl = true;
       smtp.Send(mail);

Tuesday, 23 July 2013

check only one checkbox among multiple check boxes in gridview

add the below script in your html head section

<script type="text/javascript">
        function CheckOne(obj) {
            var grid = obj.parentNode.parentNode.parentNode;
            var inputs = grid.getElementsByTagName("input");
            for (var i = 0; i < inputs.length; i++) {
                if (inputs[i].type == "checkbox") {
                    if (obj.checked && inputs[i] != obj && inputs[i].checked) {
                        inputs[i].checked = false;
                    }
                }
            }
        }
    </script>


call the above function in your checkbox like:

 <asp:CheckBox ID="chkinner" runat="server" AutoPostBack="true" onclick="CheckOne(this);"
                                                                                OnCheckedChanged="chkinner_CheckedChanged" />

display gmap on a asp.net page

First Download Gmap.dll file add it to solution

Add the following page directive:

<%@ Register Assembly="GMaps" Namespace="Subgurim.Controles" TagPrefix="cc1" %>


and then add the following code which position you display the gmap

 <cc1:GMap ID="GMap1" runat="server" Height="365px" Width="700px" />

u can edit height and width