Friday, December 30, 2011

Show the msg before deleting data from the grid view in asp.net


i wrote the code in source window,

<asp:button  id="btn1" OnClientClick="javascript:return confirm('Are you sure you want to Delete this Record!');"   ></asp:button>

(or)

function confirm_Delete() {
                var msg = confirm("Are you sure you want to Delete this Record!");

                if (msg == true) {
                    alert("Record Deleted");
                    return true;
                }
                else {
                    return false;
                }
            }

Thursday, December 29, 2011

How to get the ID from db using Datakeys in ASP.NET



source page:
========
<gridview   ........ DataKeyNames="IdeaID"   ></gridview>
Code Behind:
=========

 protected void grdMyIdea_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
             
                if (e.CommandName == "Edit")
                {
                    Response.Redirect("Idea.aspx?Ideaid=" +e.CommandArgument );
                }
                if(e.CommandName == "Delete")
                {
                    int intValue = 0;
                    DataAccessLayer _objDAL = new DataAccessLayer();
                    GridViewRow row = (GridViewRow)(((ImageButton)e.CommandSource).NamingContainer);
                    int IdeaID = Convert.ToInt32(((System.Web.UI.WebControls.GridView)   (sender)).DataKeys[row.RowIndex].Value);
                    SqlParameter[] _sqlparam = new SqlParameter[1];
                    _sqlparam[0] = new SqlParameter("@Ideaid", IdeaID);
                    intValue = _objDAL.Manipulation("THRSP_MyideaDelete", _sqlparam);
                    GetdataMyidea();
                   
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

Thursday, December 22, 2011

Send Email Functionality using ASP.NET with c sharp


Web.config file:
===========
<configuration>
  <appSettings>
    <add key="Email" value="chitharan89@gmail.com"/>
  </appSettings>
  <system.net>
    <mailSettings>
      <smtp >
        <network host="127.0.0.1" port="25" userName ="chitharan89@gmail.com" password ="9715929121" />
      </smtp>
    </mailSettings>
  </system.net>
<connectionStrings>
<add name="connection" connectionString="Data Source=SPTEST;database=db1;Integrated Security=True;  "/>
</connectionStrings>
</configuration>

protected void imgBtnshare_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                string FromEmail = ConfigurationManager.AppSettings["Email"].ToString();
                string ToEmail = "chitharan89@gmail.com";
                MailMessage Message = new MailMessage(FromEmail, ToEmail);
                Message.Subject = "To Share the Idea to Friends";
                Message.Body = "The main Purpose sharing ideas to friend and get reply ";                              
                Message.IsBodyHtml = true;
                SmtpClient SMTP = new SmtpClient();
                SMTP.Send(Message);
               
               
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);

            }

        }

Fetch the gridview data and display next page textboxes throw Query string using ASP.NET


 protected void grdMyIdea_RowCommand(object sender, GridViewCommandEventArgs e)
        { 
            try
            {
              
                if (e.CommandName == "Edit")
                {
                    Response.Redirect("sampleidea.aspx?Ideaid=" +e.CommandArgument );
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

ANOTHER PAGE: Ideaid is primarykey is also used in this table..fetch by another table Title and Description how? 

 protected void Page_Load(object sender, EventArgs e)
 {
           int Ideaid = 0;
           Ideaid = Convert.ToInt32(Request.QueryString["Ideaid"].ToString());
          
            if (!IsPostBack)
            {
                Getdata();
            }

public void Getdata()
        {
            SqlConnection con = new SqlConnection(connection);
            con.Open();
            SqlDataAdapter da = new SqlDataAdapter("select Title,Description from Idea where Ideaid='" + Request.QueryString["Ideaid"].ToString() + "'", con);
            con.Close();
            DataSet ds = new DataSet();
            da.Fill(ds);
            TextBox1.Text = ds.Tables[0].Rows[0]["Title"].ToString();
            TextBox2.Text = ds.Tables[0].Rows[0]["Description"].ToString();
           
           
        }
 

Wednesday, December 21, 2011

Show msg onclick client side only using source file code.

OnClientClick="return confirm('Edit the file permanently ?');"

Grid view Serial No count will be generated automatically using this Code


protected void grid1_RowDataBound(object sender, gridviewRowDataBound e)
{
 if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lblno = (Label)e.Row.FindControl("lblSerialNo");
                lblno.Text = ((grdMyIdea.PageIndex * grdMyIdea.PageSize) + e.Row.RowIndex + 1).ToString();
            }
}

Tuesday, December 20, 2011

Display current year, month and date


--Display name of the current month and Year--
Select DateName( Month, getDate() ) + ' ' + DateName( Year, getDate() )
--Display current year, month and date--
 SELECT 'Year: ' + CONVERT(VarChar(4), YEAR(GETDATE()))    + ', Month: ' + CONVERT(VarChar(2), MONTH(GETDATE()))
    + ', Day: ' + CONVERT(VarChar(2), DAY(GETDATE()))

Creating procedure used for Diplaying current year of quater months data's should be Visible.



CREATE PROC [dbo].[THRSP_CurrentQuaterIdea]
AS
BEGIN
DECLARE @month INT;
SET @month=MONTH (GETDATE())
IF(@month =1 or @month=2 or @month =3)
BEGIN
SELECT *FROM Idea WHERE YEAR(CreatedOn)=YEAR(GETDATE()) and MONTH(CreatedOn) in (1,2,3)
END
ELSE IF(@month =4 or @month=5 or @month =6)
BEGIN
SELECT *FROM Idea WHERE YEAR(CreatedOn)=YEAR(GETDATE()) and MONTH(CreatedOn) in (4,5,6)
END
ELSE IF(@month =7 or @month=8 or @month =9)
BEGIN
SELECT *FROM Idea WHERE YEAR(CreatedOn)=YEAR(GETDATE()) and MONTH(CreatedOn) in (7,8,9)
END
ELSE IF(@month =10 or @month=11 or @month =12)
BEGIN
SELECT *FROM Idea WHERE YEAR(CreatedOn)=YEAR(GETDATE()) and MONTH(CreatedOn) in (10,11,12)
END

END


GO

Thursday, December 15, 2011

Show the lastweek, Today, Mostvotes, Leastvotes,Noofvotes using a sp in Sql Server


USE [db1]
GO

/****** Object:  StoredProcedure [dbo].[THRSP_ShowListOfIdea]    Script Date: 12/16/2011 10:34:51 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

ALTER proc [dbo].[THRSP_ShowListOfIdea]
(
@Showme varchar(20)
)
AS
IF(@Showme='Last Week')
BEGIN
declare @fromdate datetime;
declare @enddate datetime;
set @fromdate=(select convert(datetime, (convert (varchar(10), getdate(),101))))
set @enddate=(select convert(datetime, (convert (varchar(10), getdate()-7,101))))
select Title,Description from Idea where CreatedOn between  @enddate and @fromdate
END

ELSE IF(@Showme='Today')
BEGIN
Declare @today datetime;
set @today =(select convert(datetime, (convert (varchar(10), getdate(),101))))
SELECT i.Title, i.Description from idea i INNER JOIN votes v on i.ideaid=v.ideaid where
(year (v.VotedOn)=year(@today)and  month (v.VotedOn)=month(@today)and  day (v.VotedOn)=day(@today))
END

ELSE IF(@Showme='Most votes')
BEGIN
select * from (
SELECT i.Title, i.Description
,(select COUNT(ideaid) from Votes where ideaid=v.ideaid)as ideacount
from idea i INNER JOIN votes v on i.ideaid=v.ideaid ) as tempTable
order by ideacount desc
END

ELSE IF(@Showme='Least Votes')
BEGIN
select * from (
SELECT i.Title, i.Description
,(select COUNT(ideaid) from Votes where ideaid=v.ideaid)as ideacount
from idea i INNER JOIN votes v on i.ideaid=v.ideaid ) as tempTable
order by ideacount ASC
END
ELSE IF(@Showme='Number Of Votes')
BEGIN
SELECT i.Title, i.Description from idea i INNER JOIN votes v on i.ideaid=v.ideaid
END

GO


Wednesday, December 14, 2011

Displaying current date last week date using sql server


declare @fromdate datetime;
declare @enddate datetime;
set @fromdate=(select convert(datetime, (convert (varchar(10), getdate(),101))))
set @enddate=(select convert(datetime, (convert (varchar(10), getdate()-2,101))))

select *from Votes where VotedOn between  @enddate and @fromdate

Tuesday, December 13, 2011

Show the date ,hour and day with message in sql server.


select top(3) IdeaID,Comments ,
Case when (CONVERT (INT, DATEDIFF(minute,CommentedOn,GETDATE()))>1439)
then CONVERT(varchar(20), CONVERT (INT, DATEDIFF(minute,CommentedOn,GETDATE()))/1440 ) +' days'
 when (CONVERT (INT, DATEDIFF(minute,CommentedOn,GETDATE()))>=60)
then CONVERT(varchar(20),CONVERT (INT, DATEDIFF(minute,CommentedOn,GETDATE()))/60) + ' hours'
else
CONVERT(varchar(20),CONVERT (INT, DATEDIFF(minute,CommentedOn,GETDATE()))) + 'minutes'
End   from comments order by CommentedOn desc

Monday, December 12, 2011

Display the how many day's ,hours,minites and seconds using sql server


select
DATEDIFF(day,2007-11-30,2007-11-20) AS NumberOfDays,
DATEDIFF(hour,2007-11-30,2007-11-20) AS NumberOfHours,
DATEDIFF(minute,'2011-12-12 05:43:06.007','2011-12-12 05:45:12.100') AS NumberOfMinutes,
DATEDIFF(second,'2011-12-12 05:45:06.007','2011-12-12 05:45:06.007') AS NumberOfSecond

Friday, December 2, 2011

Mouse over Event (image), when u move over the image display the another image using Javascript

<
<
html xmlns="http://www.w3.org/1999/xhtml">head runat="server">
</
<
<title></title>head>body><form id="form1" runat="server"><div><asp:Image ID="Image1" runat="server" Width="60px" Height="80px" ImageUrl="~/Lighthouse.jpg" onmouseover="ShowBiggerImage(this);" onmouseout="ShowDefaultImage(this);"/></div><div id="LargeImageContainerDiv" style="position: absolute; z-index:2"></div></form><script type="text/javascript" language="ecmascript">
document.getElementById(
}

document.getElementById(
}

event = event || window.event;
LargeImageContainerDiv.style.left = event.clientX + document.body.scrollLeft + 10;
LargeImageContainerDiv.style.top = event.clientY + document.body.scrollTop + 10;
}
document.onmousemove = move_Area;


</
</
function ShowBiggerImage(obj) {"LargeImageContainerDiv").innerHTML = "<img src='" + obj.src + "'+'width=150 height=200' >";function ShowDefaultImage(obj) {"LargeImageContainerDiv").innerHTML = "";function move_Area(event) {</script>body>html>

Thursday, December 1, 2011

Not allowed for redirect to page(Im using Quality Functional Deployment-QFD)

ScriptManager.RegisterStartupScript(this, this.GetType(),
 "Javascript", "javascript:collapseAll(4);", true);

Disable textbox and not placed cursor in textbox.

function SetCheckBoxStatus() {

if (document.getElementById("<%=chkShow.ClientID%>").checked) {
document.getElementById("<%=txtArticleBody.ClientID%>").disabled = true;
document.getElementById("<%=fuThumbnailImage.ClientID%>").disabled = true;

}
else {
document.getElementById("<%=txtArticleBody.ClientID%>").disabled = false;
document.getElementById("<%=fuThumbnailImage.ClientID%>").disabled = false;

}
}