http://www.dotnetfunda.com/articles/article884-import-gmail-contacts-into-aspnet-gridview-.aspx
Thursday, July 28, 2011
Reading contacts from gmail
http://code.google.com/p/google-gdata/downloads/detail?name=Google_Data_API_Setup_1.8.0.0.msi&can=2&q= (api link)
http://isharpnote.com/isharpnote/post/2011/03/01/google_contact_import_aspnet.aspx
using Google.Contacts;
using Google.GData.Client;
using Google.GData.Contacts;
using Google.GData.Extensions;
<form id="form1" runat="server">
<div><b>Email Address :</b> <br />
<asp:TextBox ID="txtEmail" runat="server"> </asp:TextBox><br /><br /><b>Password :</b> <br />
<asp:TextBox ID="txtPassword" runat="server" TabIndex="1" TextMode="Password"></asp:TextBox><br /> <br />
<asp:Button ID="btnContacts" runat="server" onclick="btnContacts_Click"
TabIndex="2" Text="Import Contacts" Width="125px" /><br /> <br /> <br />
<b>Contacts:<br /> </b>
<asp:ListBox ID="lstContacts" runat="server" Height="176px" Width="229px"></asp:ListBox><br /> <br />
</div>
</form>
protected void btnContacts_Click(object sender, EventArgs e)
{
//Provide Login Information
RequestSettingsrsLoginInfo = new RequestSettings(" ", txtEmail.Text, txtPassword.Text);
rsLoginInfo.AutoPaging = true;
// Fetch contacts and dislay them in ListBox
ContactsRequestcRequest = new ContactsRequest(rsLoginInfo);
Feed <contact>feedContacts = cRequest.GetContacts();
foreach (Contact gmailAddresses in feedContacts.Entries)
{
Console.WriteLine("\t" + gmailAddresses.Title);
lstContacts.Items.Add(gmailAddresses.Title);
foreach (EMailemailId in gmailAddresses.Emails)
{
Console.WriteLine("\t" + emailId.Address);
lstContacts.Items.Add(" " + emailId.Address);
}
}
}
http://isharpnote.com/isharpnote/post/2011/03/01/google_contact_import_aspnet.aspx
using Google.Contacts;
using Google.GData.Client;
using Google.GData.Contacts;
using Google.GData.Extensions;
<form id="form1" runat="server">
<div><b>Email Address :</b> <br />
<asp:TextBox ID="txtEmail" runat="server"> </asp:TextBox><br /><br /><b>Password :</b> <br />
<asp:TextBox ID="txtPassword" runat="server" TabIndex="1" TextMode="Password"></asp:TextBox><br /> <br />
<asp:Button ID="btnContacts" runat="server" onclick="btnContacts_Click"
TabIndex="2" Text="Import Contacts" Width="125px" /><br /> <br /> <br />
<b>Contacts:<br /> </b>
<asp:ListBox ID="lstContacts" runat="server" Height="176px" Width="229px"></asp:ListBox><br /> <br />
</div>
</form>
protected void btnContacts_Click(object sender, EventArgs e)
{
//Provide Login Information
RequestSettingsrsLoginInfo = new RequestSettings(" ", txtEmail.Text, txtPassword.Text);
rsLoginInfo.AutoPaging = true;
// Fetch contacts and dislay them in ListBox
ContactsRequestcRequest = new ContactsRequest(rsLoginInfo);
Feed <contact>feedContacts = cRequest.GetContacts();
foreach (Contact gmailAddresses in feedContacts.Entries)
{
Console.WriteLine("\t" + gmailAddresses.Title);
lstContacts.Items.Add(gmailAddresses.Title);
foreach (EMailemailId in gmailAddresses.Emails)
{
Console.WriteLine("\t" + emailId.Address);
lstContacts.Items.Add(" " + emailId.Address);
}
}
}
Thursday, July 21, 2011
get the other columns data using command argument in grideview
if (e.CommandName == "setfinactive")
{
//GridViewRow row = GridView2.Rows[index];
GridViewRow gvr = (GridViewRow)((Control)e.CommandSource).NamingContainer;
LinkButton pEdit = (LinkButton)gvr.FindControl("lblcourseid");
userid = e.CommandArgument.ToString();
courseid = Convert.ToInt32(pEdit.Text);
//con.Open();
//cmd = new SqlCommand("update usercourse set FInactive1 = 4 where userid = ");
//con.Close();
}
{
//GridViewRow row = GridView2.Rows[index];
GridViewRow gvr = (GridViewRow)((Control)e.CommandSource).NamingContainer;
LinkButton pEdit = (LinkButton)gvr.FindControl("lblcourseid");
userid = e.CommandArgument.ToString();
courseid = Convert.ToInt32(pEdit.Text);
//con.Open();
//cmd = new SqlCommand("update usercourse set FInactive1 = 4 where userid = ");
//con.Close();
}
Friday, July 15, 2011
confirmation box using gridview control when delete button click
under.aspx
-----------
<asp:GridView DataKeyNames="sno" ID="GridView1"
runat="server" AutoGenerateColumns="False"
OnRowCommand="GridView1_RowCommand"
OnRowDataBound="GridView1_RowDataBound"
OnRowDeleted="GridView1_RowDeleted" OnRowDeleting="GridView1_RowDeleting">
<Columns>
<asp:BoundField DataField="sno" HeaderText="sno" />
<asp:BoundField DataField="name" HeaderText="name" />
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1"
CommandArgument='<%# Eval("sno") %>'
CommandName="Delete" runat="server">
Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp: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;
using System.Data.SqlClient;
using System.Configuration;
public partial class dummy : System.Web.UI.Page
{
SqlConnection con = null;
SqlCommand cmd = null;
SqlDataReader dr = null;
protected void Page_Load(object sender, EventArgs e)
{
con = new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ConnectionString);
con.Open();
cmd = new SqlCommand("select sno,name from dummy",con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton l = (LinkButton)e.Row.FindControl("LinkButton1");
l.Attributes.Add("onclick", "javascript:return " +
"confirm('Are you sure you want to delete this record " +
DataBinder.Eval(e.Row.DataItem, "sno") + "')");
}
}
protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
// get the categoryID of the clicked row
int sno = Convert.ToInt32(e.CommandArgument);
// Delete the record
// DeleteRecordByID(categoryID);
con.Open();
cmd = new SqlCommand("delete from dummy where sno=@sno", con);
cmd.Parameters.Add(new SqlParameter("@sno", sno));
cmd.ExecuteNonQuery();
con.Close();
// Implement this on your own :)
}
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int sno = (int)GridView1.DataKeys[e.RowIndex].Value;
// DeleteRecordByID(categoryID);
con.Open();
cmd = new SqlCommand("delete from dummy where sno=@sno",con);
cmd.Parameters.Add(new SqlParameter("@sno",sno));
cmd.ExecuteNonQuery();
con.Close();
}
protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
{
}
}
-----------
<asp:GridView DataKeyNames="sno" ID="GridView1"
runat="server" AutoGenerateColumns="False"
OnRowCommand="GridView1_RowCommand"
OnRowDataBound="GridView1_RowDataBound"
OnRowDeleted="GridView1_RowDeleted" OnRowDeleting="GridView1_RowDeleting">
<Columns>
<asp:BoundField DataField="sno" HeaderText="sno" />
<asp:BoundField DataField="name" HeaderText="name" />
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1"
CommandArgument='<%# Eval("sno") %>'
CommandName="Delete" runat="server">
Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp: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;
using System.Data.SqlClient;
using System.Configuration;
public partial class dummy : System.Web.UI.Page
{
SqlConnection con = null;
SqlCommand cmd = null;
SqlDataReader dr = null;
protected void Page_Load(object sender, EventArgs e)
{
con = new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ConnectionString);
con.Open();
cmd = new SqlCommand("select sno,name from dummy",con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton l = (LinkButton)e.Row.FindControl("LinkButton1");
l.Attributes.Add("onclick", "javascript:return " +
"confirm('Are you sure you want to delete this record " +
DataBinder.Eval(e.Row.DataItem, "sno") + "')");
}
}
protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
// get the categoryID of the clicked row
int sno = Convert.ToInt32(e.CommandArgument);
// Delete the record
// DeleteRecordByID(categoryID);
con.Open();
cmd = new SqlCommand("delete from dummy where sno=@sno", con);
cmd.Parameters.Add(new SqlParameter("@sno", sno));
cmd.ExecuteNonQuery();
con.Close();
// Implement this on your own :)
}
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int sno = (int)GridView1.DataKeys[e.RowIndex].Value;
// DeleteRecordByID(categoryID);
con.Open();
cmd = new SqlCommand("delete from dummy where sno=@sno",con);
cmd.Parameters.Add(new SqlParameter("@sno",sno));
cmd.ExecuteNonQuery();
con.Close();
}
protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
{
}
}
display alert by by using serverside code(works fine)
<asp:Button ID="ApproveButton" runat="server" CausesValidation="False" Text="ravi"
OnClientClick="return confirm('Are you certain you want to approve this record?');"
onclick="ApproveButton_Click" />
OnClientClick="return confirm('Are you certain you want to approve this record?');"
onclick="ApproveButton_Click" />
If the user clicks OK your normal click code will run but if they cancel the function returns false so the click won't be processed.
display alert by using serverside code
string str = "Are you sure, you want to Approve this Record?";
this.ClientScript.RegisterStartupScript(typeof(Page), "Popup", "ConfirmApproval('" + str + "');", true);
this.ClientScript.RegisterStartupScript(typeof(Page), "Popup", "ConfirmApproval('" + str + "');", true);
Wednesday, July 13, 2011
repeater control code
http://www.netrostar.com/Tutorials-91-ASP.NET%20Tutorial.%20How%20to%20use%20Repeater
Monday, July 11, 2011
mailattachment code
protected void LinkButton1_Click(object sender, EventArgs e)
{
MailMessage message = new MailMessage();
message.To.Add(new MailAddress("ravivarma_07d@yahoo.com"));
// message.From = new MailAddress("ravivarma_07d@yahoo.com");
message.Subject = "Testing";
message.Body = "we are sending test mail";
message.BodyEncoding = System.Text.Encoding.UTF8;
message.SubjectEncoding = System.Text.Encoding.UTF8;
Attachment attach = new Attachment(FileUpload1.PostedFile.InputStream,FileUpload1.FileName);
message.Attachments.Add(attach);
message.Priority = MailPriority.Normal;
string err = "";
SmtpClient smtpClient1 = new System.Net.Mail.SmtpClient();
try
{
smtpClient1.Send(message);
}
catch (SmtpFailedRecipientException ex)
{
err = ex.Message;
}
catch (SmtpException ex)
{
err = ex.Message;
}
}
{
MailMessage message = new MailMessage();
message.To.Add(new MailAddress("ravivarma_07d@yahoo.com"));
// message.From = new MailAddress("ravivarma_07d@yahoo.com");
message.Subject = "Testing";
message.Body = "we are sending test mail";
message.BodyEncoding = System.Text.Encoding.UTF8;
message.SubjectEncoding = System.Text.Encoding.UTF8;
Attachment attach = new Attachment(FileUpload1.PostedFile.InputStream,FileUpload1.FileName);
message.Attachments.Add(attach);
message.Priority = MailPriority.Normal;
string err = "";
SmtpClient smtpClient1 = new System.Net.Mail.SmtpClient();
try
{
smtpClient1.Send(message);
}
catch (SmtpFailedRecipientException ex)
{
err = ex.Message;
}
catch (SmtpException ex)
{
err = ex.Message;
}
}
Saturday, July 9, 2011
pdf certificate
http://www.mikesdotnetting.com/Article/80/Create-PDFs-in-ASP.NET-getting-started-with-iTextSharp
Sunday, July 3, 2011
reading url form web.config (wcf service)
In Web.config:
<appSettings>
<add key="wsUrl" value="http://192.168.1.7:650/CafeService.svc"/>
</appSettings>
in the .aspx page declare a globle variable
var wsurl;
in document.ready
wsurl = '<%=ConfigurationManager.AppSettings["WsUrl"].ToString() %>';
<appSettings>
<add key="wsUrl" value="http://192.168.1.7:650/CafeService.svc"/>
</appSettings>
in the .aspx page declare a globle variable
var wsurl;
in document.ready
wsurl = '<%=ConfigurationManager.AppSettings["WsUrl"].ToString() %>';
Saturday, July 2, 2011
date formats
Declare @d datetime
select @d = getdate()
select @d as OriginalDate,
convert(varchar,@d,100) as ConvertedDate,
100 as FormatValue,
'mon dd yyyy hh:miAM (or PM)' as OutputFormat
union all
select @d,convert(varchar,@d,101),101,'mm/dd/yy'
union all
select @d,convert(varchar,@d,102),102,'yy.mm.dd'
union all
select @d,convert(varchar,@d,103),103,'dd/mm/yy'
union all
select @d,convert(varchar,@d,104),104,'dd.mm.yy'
union all
select @d,convert(varchar,@d,105),105,'dd-mm-yy'
union all
select @d,convert(varchar,@d,106),106,'dd mon yy'
union all
select @d,convert(varchar,@d,107),107,'Mon dd, yy'
union all
select @d,convert(varchar,@d,108),108,'hh:mm:ss'
union all
select @d,convert(varchar,@d,109),109,'mon dd yyyy hh:mi:ss:mmmAM (or PM)'
union all
select @d,convert(varchar,@d,110),110,'mm-dd-yy'
union all
select @d,convert(varchar,@d,111),111,'yy/mm/dd'
union all
select @d,convert(varchar,@d,112),112,'yymmdd'
union all
select @d,convert(varchar,@d,113),113,'dd mon yyyy hh:mm:ss:mmm(24h)'
union all
select @d,convert(varchar,@d,114),114,'hh:mi:ss:mmm(24h)'
union all
select @d,convert(varchar,@d,120),120,'yyyy-mm-dd hh:mi:ss(24h)'
union all
select @d,convert(varchar,@d,121),121,'yyyy-mm-dd hh:mi:ss.mmm(24h)'
union all
select @d,convert(varchar,@d,126),126,'yyyy-mm-dd Thh:mm:ss:mmm(no spaces)'
select @d = getdate()
select @d as OriginalDate,
convert(varchar,@d,100) as ConvertedDate,
100 as FormatValue,
'mon dd yyyy hh:miAM (or PM)' as OutputFormat
union all
select @d,convert(varchar,@d,101),101,'mm/dd/yy'
union all
select @d,convert(varchar,@d,102),102,'yy.mm.dd'
union all
select @d,convert(varchar,@d,103),103,'dd/mm/yy'
union all
select @d,convert(varchar,@d,104),104,'dd.mm.yy'
union all
select @d,convert(varchar,@d,105),105,'dd-mm-yy'
union all
select @d,convert(varchar,@d,106),106,'dd mon yy'
union all
select @d,convert(varchar,@d,107),107,'Mon dd, yy'
union all
select @d,convert(varchar,@d,108),108,'hh:mm:ss'
union all
select @d,convert(varchar,@d,109),109,'mon dd yyyy hh:mi:ss:mmmAM (or PM)'
union all
select @d,convert(varchar,@d,110),110,'mm-dd-yy'
union all
select @d,convert(varchar,@d,111),111,'yy/mm/dd'
union all
select @d,convert(varchar,@d,112),112,'yymmdd'
union all
select @d,convert(varchar,@d,113),113,'dd mon yyyy hh:mm:ss:mmm(24h)'
union all
select @d,convert(varchar,@d,114),114,'hh:mi:ss:mmm(24h)'
union all
select @d,convert(varchar,@d,120),120,'yyyy-mm-dd hh:mi:ss(24h)'
union all
select @d,convert(varchar,@d,121),121,'yyyy-mm-dd hh:mi:ss.mmm(24h)'
union all
select @d,convert(varchar,@d,126),126,'yyyy-mm-dd Thh:mm:ss:mmm(no spaces)'
Subscribe to:
Posts (Atom)