Monday, May 20, 2013

Free Google Adsense code

its complete free ad  Adsense code 


you can implement google Adsense code where ever you need to show ad in your site .

steps for implement :

1. copy the below 2 script 
2.goto your application page (any application like , html ,.net ,php....etc.)
3. this ad size width  is 300px and height is 250px;
4.just paste the code where you want to show the ad in your site.
5.you can use n number place in your site.
6.this is demo Adsense  code for checking your site. 


Script for Ad :

first Script

 <script type="text/javascript">
<!--
          google_ad_client = "ca-pub-3004748698247519";
          /* Free Google Adsense*/
          google_ad_slot = "2262531382";
          google_ad_width = 300;
          google_ad_height = 250;
//-->
 </script>

second Script

 <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
 </script>

Tuesday, May 14, 2013

Maintaining State of CheckBoxes While Paging in a GridView Control

Introduction:
In this article I will explain how to maintain state of selected checkboxes during paging in gridview using asp.net
Description: 

I have one gridview with checkboxes and it contains lot of data for that reason I applied paging for gridview and displaying 8 records per page. After apply the paging in gridview if I select checkboxes in first page and moving to another page and select some checkboxes in second page after that if I come back I am unable to see the previous selected values. At that time I know one new thing that is gridview won’t maintain the state of controls during postback for that reason we need write some code to maintain the previous selected values in gridview. Before seeing the code implemention first Design your aspx page like this


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Maintain State Checkboxes during paging</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView runat="server" ID="gvdetails" AllowPaging="true" AllowSorting="true"AutoGenerateColumns="false" onpageindexchanging="gvdetails_PageIndexChanging" PageSize="8"DataKeyNames="UserId">
<RowStyle BackColor="#EFF3FB" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UserId" HeaderText="UserId" />
<asp:BoundField DataField="UserName" HeaderText="UserName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:BoundField DataField="Location" HeaderText="Location" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
After completion of aspx page design add the following references in code behind


using System.Collections;
using System.Data;
using System.Data.SqlClient;



After completion of adding reference write the following code in code behind


protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
BindGridData();
}
}
//This method is used to bind the gridview
protected void BindGridData()
{
SqlConnection con = new SqlConnection("Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MySampleDB");
SqlCommand cmd = new SqlCommand("select * from UserInformation", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
gvdetails.DataSource = ds;
gvdetails.DataBind();
}
protected void gvdetails_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
SaveCheckedValues();
gvdetails.PageIndex = e.NewPageIndex;
BindGridData();
PopulateCheckedValues();
}
//This method is used to populate the saved checkbox values
private void PopulateCheckedValues()
{
ArrayList userdetails = (ArrayList)Session["CHECKED_ITEMS"];
if (userdetails != null && userdetails.Count > 0)
{
foreach (GridViewRow gvrow in gvdetails.Rows)
{
int index = (int)gvdetails.DataKeys[gvrow.RowIndex].Value;
if (userdetails.Contains(index))
{
CheckBox myCheckBox = (CheckBox)gvrow.FindControl("chkSelect");
myCheckBox.Checked = true;
}
}
}
}
//This method is used to save the checkedstate of values
private void SaveCheckedValues()
{
ArrayList userdetails = new ArrayList();
int index = -1;
foreach (GridViewRow gvrow in gvdetails.Rows)
{
index = (int)gvdetails.DataKeys[gvrow.RowIndex].Value;
bool result = ((CheckBox)gvrow.FindControl("chkSelect")).Checked;

// Check in the Session
if (Session["CHECKED_ITEMS"] != null)
userdetails = (ArrayList)Session["CHECKED_ITEMS"];
if (result)
{
if (!userdetails.Contains(index))
userdetails.Add(index);
}
else
userdetails.Remove(index);
}
if (userdetails != null && userdetails.Count > 0)
Session["CHECKED_ITEMS"] = userdetails;
}

If you observe above code I written one method to bind our gridview and written two more methods those are SaveCheckedValues and PopulateCheckedValues these two methods are used to maintain the state of selected checkbox values during paging in gridview. In SaveCheckedValues method I used Session variable to maintain the selected checkbox values after that by using this saved session values I am populating the checkbox state in PopulateCheckedValues method.

how to import Contacts from GMAIL using ASP.NET and C#


Introduction:

In this article I will explain how to import gmail contacts of a user by using GContacts Data API provided by Google.

Description:

We have developed one social network site at that time we think that how to popularize the our social network site I have checked some of social network sites at that time we got idea to implement import contacts concept is best to intimate all of our friends at a time I have searched so many websites to implement this concepts but no result finally I have implemented import contacts from gmail 

I used ASP.NET and C# for developing this application.
We need to follow below steps to get gmail contacts 

Step-1:  Download Google data API setup from the specified URL 

Or you can directly download with the following

That Set Up will installs set of Google Data dll’s (Google.GData.Apps.dll, Google.GData.Client.dll, Google.GData.Contacts.dll, Google.GData.Extensions.dll) into client installed Machine, you should collect that dll’s for your program.

Step-2:  Design our aspx page (Default.aspx) by using with the following UI as simple scenario.


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>IMport Gmail Contacts</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
UserName</td>
<td>
<asp:TextBox ID="txtgmailusername" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Password</td>
<td>
<asp:TextBox ID="txtpassword" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</td>
</tr>
</table>
</div>
<div>
<asp:GridView ID="gvmails" runat="server"></asp:GridView>
</div>
</form>
</body>
</html>
Step-3:  Add those downloaded google dll’s as reference to your website in visual studio->Solution Explorer ->Right Click-> Click on Add Reference….->Browse ->Get dll’s from Installed Location->Press OK.

Step-4:
A) Add namespace these namespace to your code behind

using Google.GData.Contacts;
using Google.GData.Client;
using Google.GData.Extensions;
using Google.Contacts;
B) After that write following code in code behind


public static DataSet GetGmailContacts(string App_Name, string Uname, string UPassword)
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
DataColumn C2 = new DataColumn();
C2.DataType = Type.GetType("System.String");
C2.ColumnName = "EmailID";
dt.Columns.Add(C2);
RequestSettings rs = new RequestSettings(App_Name, Uname, UPassword);
rs.AutoPaging = true;
ContactsRequest cr = new ContactsRequest(rs);
Feed<Contact> f = cr.GetContacts();
foreach (Contact t in f.Entries)
{
foreach (EMail email in t.Emails)
{
DataRow dr1 = dt.NewRow();
dr1["EmailID"] = email.Address.ToString();
dt.Rows.Add(dr1);
}
}
ds.Tables.Add(dt);
return ds;
}
protected void Button1_Click(object sender, EventArgs e)
{
DataSet ds = GetGmailContacts("MyNetwork Web Application!", txtgmailusername.Text, txtpassword.Text);
gvmails.DataSource = ds;
gvmails.DataBind();
}

- Copyright © velamca09 - velayudham - Powered by Blogger - Designed by velayudham -