Friday, January 20, 2012

update Content of page by admin throw sqldatabase

Admin page...............
Imports System.Data
Imports System.Data.SqlClient

Partial Class admin_Default
    Inherits System.Web.UI.Page
    Public con As SqlConnection
    Public da As SqlDataAdapter
    Public ds As DataSet
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
  con = New SqlConnection("Data Source=OM;Initial Catalog=effort;Integrated Security=True")
 da = New SqlDataAdapter("update page set p_title='" + TextBox1.Text + "',p_description='" +      TextBox2.Text + "',dec='" + Editor1.Content.ToString + "'", con)
   ds = New DataSet
   da.Fill(ds)
   Catch ex As Exception
   Response.Write(ex.Message)
    End Try
    End Sub
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
client.................................
write namespace....
    Function fill() As String
        Try
            con = New SqlConnection("Data Source=OM;Initial Catalog=effort;Integrated Security=True")
            ds = New DataSet
            da = New SqlDataAdapter("select * from page", con)
            da.Fill(ds)
            Label1.Text = ds.Tables(0).Rows(0).Item("dec")
            Label2.Text = ds.Tables(0).Rows(1).Item("p_title")
            Label3.Text = ds.Tables(0).Rows(2).Item("p_description")
           Catch ex As Exception
            Response.Write(ex.Message)

End Try
    End Function
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        fill()
    End Sub

Friday, January 13, 2012

Update data using Admin Panel

write code at the Admin Page 
Add Namespace and add the XML file by Solution Explorer
*********************
Imports System.Xml
Imports System.Web
**********************
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim strxmlpath As String = Server.MapPath("../database/col.xml")
            Dim doc As New XmlDocument
            doc.Load(strxmlpath)
            Dim node As XmlNode = doc.DocumentElement.FirstChild
            node.InnerText = Editor1.Content.ToString  //add the editor on the page
            doc.Save(strxmlpath)
        Catch ex As Exception
            Response.Write(ex.Message)

        End Try
    End Sub
    Public Function xmlshwo2()
        Try
            Dim strxmlpath1 As String = Server.MapPath("../database/col.xml")
            Dim doc As New XmlDocument
            doc.Load(strxmlpath1)
            Dim elem As XmlNode = doc.DocumentElement.FirstChild
            Editor1.Content = elem.InnerText
            doc.Save(strxmlpath1)
        Catch ex As Exception
            Response.Write(ex.Message)
        End Try
    End Function

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            xmlshwo2()
        End If
    End Sub
write the code on  client  page

Public Function xmlshow1()
        Try
            Dim strxmlpath As String = Server.MapPath("~/database/col.xml")
            Dim doc As New XmlDocument
            doc.Load(strxmlpath)
            Dim elem As XmlNode = doc.DocumentElement.FirstChild
            Label1.Text = elem.InnerText
        Catch ex As Exception
            Response.Write(ex.Message)
        End Try
    End Function

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        xmlshow1()
    End Sub

Monday, January 9, 2012

Change the background color in same page

***********************
write this code under head> tag
***********************
script type="text/javascript">
function init()
{
document.body.onclick = function()
{
colorChange();
}
function colorChange()
{
var colors = ["red","green","blue","orange","pink"];
var index = Math.floor(Math.random() * 100) % 5;
document.body.style.background = colors[index];
}
}
window.onload = init;
/script>

Friday, January 6, 2012

Sending Email From Your Gmail Account in C#.net

Use these namespace and add function to your event on which you want to send email.
*****************************************************************
using System.Web
using System.Net
using System.Net.Mail
**********************
public void sendml()
{
try
{
SmtpClient client = new SmtpClient();
MailAddress sendto = new MailAddress("email of other person");
MailAddress from = new MailAddress("youremail");
MailMessage message = new MailMessage(from, sendto);
message.IsBodyHtml = true;
message.Subject = "Test by Sandeep";
string st = "Emp Name:" + TextBox1.Text.ToString() + "
Login Time:" + TextBox2.Text.ToString() + "
Logout Time:" + TextBox3.Text + "
Host Name:" + TextBox4.Text + "
Description:" + TextBox5.Text + "";
message.Body = st;
message.IsBodyHtml = true;
NetworkCredential basicauthantication =new NetworkCredential("emailid@gmail.com", "password");
client.Host = "smtp.gmail.com";
client.UseDefaultCredentials = false;
client.Credentials = basicauthantication;
client.EnableSsl = true;
client.Send(message);
Response.Write("mail has been sent");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}

Data insert in Gridview

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data;
public partial class form : System.Web.UI.Page
{
OleDbCommand cmd;
OleDbConnection cn;
OleDbDataAdapter da;
DataSet ds;

protected void Page_Load(object sender, EventArgs e)
{
function();
}

protected void Button2_Click(object sender, EventArgs e)
{
cn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\\Sandeep cmc\\Database21.accdb");
da = new OleDbDataAdapter("insert into userr (name1)values('"+TextBox2.Text+"')", cn);
ds = new DataSet();
da.Fill(ds);
function();

}

public void function()

{
cn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\\Sandeep cmc\\Database21.accdb");
da = new OleDbDataAdapter("select * from userr", cn);
ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();


}
}

Thursday, January 5, 2012

Show date And Time in many format

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class CurrentDate : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = System.DateTime.Now.ToString();
Label3.Text = System.DateTime.Now.ToLongDateString();
Label4.Text = System.DateTime.Now.ToLongTimeString();
Label5.Text = System.DateTime.Now.ToShortDateString();
Label6.Text = System.DateTime.Now.ToShortTimeString();
}
}

Find The Host name

private string GetIP()
{
string strHostName = " " ;
strHostName = System.Net.Dns.GetHostName();
return strHostName;
}
And write the code this secssion
protected void Page_Load(object sender, EventArgs e)
TextBox4.Text =GetIP();

Tuesday, January 3, 2012

Deleting selected rows from gridview using checkbox in vb.net

This program will show how to deleting selected rows from gridview using checkbox in vb.net

Imports System.Data

Partial Class _Default
    Inherits System.Web.UI.Page
    Public temptable As DataTable
    Public ds As DataSet
    Public editrow As DataRow
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        temptable = Session("cart")
        editrow = temptable.NewRow
        editrow("Item_Name") = TextBox1.Text
        temptable.Rows.Add(editrow)
        Session("cart") = temptable
        GridView1.DataSource = temptable
        GridView1.DataBind()
    End Sub
'function for filling datatable
    Public Function makecart()
        Try
            temptable = New DataTable("cart")
            temptable.Columns.Add("id", GetType(Integer))
            temptable.Columns("id").AutoIncrement = True
            temptable.Columns("id").AutoIncrementSeed = 1
            temptable.Columns.Add("Item_Name", GetType(String))

            'put table in session
            Session("cart") = temptable

        Catch ex As Exception
            Response.Write(ex.Message)
        End Try
    End Function

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            makecart()

        End If
    End Sub

    'delete selected items
    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        temptable = Session("cart")
        For i As Integer = 0 To temptable.Rows.Count - 1
            If CType(GridView1.Rows(i).FindControl("CheckBox1"), CheckBox).Checked = True Then
                temptable.Rows(i).Delete()
            Else
                Dim a As Integer = 0
            End If
        Next
        Session("cart") = temptable
        GridView1.DataSource = temptable
        GridView1.DataBind()
    End Sub

    'selecting all at a time this handel check box in header row  
    Protected Sub CheckBox2_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.RowCommand
        If CType(GridView1.HeaderRow.FindControl("CheckBox2"), CheckBox).Checked = True Then
            For i As Integer = 0 To GridView1.Rows.Count - 1
                CType(GridView1.Rows(i).FindControl("CheckBox1"), CheckBox).Checked = True
            Next
        Else
            For i As Integer = 0 To GridView1.Rows.Count - 1
                CType(GridView1.Rows(i).FindControl("CheckBox1"), CheckBox).Checked = False

            Next
        End If
   End Sub
End Class