"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Saturday, July 31, 2010

Ajax rating in asp.net with sample

 hi frienz,
Ajax rating is one of the nice feature they are giving 'n it's very easy t0 implement also

Demo













Documentation
u need to have a style sheet where u r controlling the rating

     <style type="text/css">
         .ratingStar{white-space:nowrap;margin:1em;height:14px;}
         .ratingStar .ratingItem {font-size: 0pt;width: 30px;height: 20px;margin: 0px;padding: 0px;display: block;background-repeat: no-repeat;cursor:pointer;}
         .ratingStar .Filled {background-image: url(pic/brightstar.JPG);}
         .ratingStar .Empty {background-image: url(pic/graystar.JPG);}
         .ratingStar .Saved {background-image: url(pic/brightstar.JPG);}
     </style>

Add ajax script manager
    <ajaxToolkit:ToolkitScriptManager runat="Server" EnableScriptGlobalization="true" EnableScriptLocalization="true" ID="ToolkitScriptManager1" />

one demo pic
 <asp:Image ImageUrl="~/pic/hair.jpg" ID="yfgdf" runat="server" />

add ajax rating control
        <ajaxToolkit:Rating runat="server" ID="rateItem" MaxRating="5" CurrentRating="1"
                             CssClass="ratingStar" StarCssClass="ratingItem" WaitingStarCssClass="Saved" 
                             FilledStarCssClass="Filled" EmptyStarCssClass="Empty" AutoPostBack="True" 
                             OnChanged="rate_Changed"  ></ajaxToolkit:Rating>

one label to show the rating
 <asp:Label ID="lblRate" runat="server"></asp:Label>
On server side

// event wil b fired on rating change
    protected void rate_Changed(object sender, AjaxControlToolkit.RatingEventArgs e)
    {
        Rate(int.Parse(e.Value));
    }

    private void Rate(int rate)
    {
        lblRate.Text = "You have rated " + rate.ToString() + " star";
        //rateItem.ReadOnly = true;
    }


Have a nice day... 'N happy Coding :)
 Programming ASP.NET AJAX: Build rich, Web 2.0-style UI with ASP.NET AJAXMicrosoft ASP.NET and AJAX: Architecting Web Applications (PRO-Developer)Programming ASP.NET AJAX

sql mail through store procedure in sql server 2005/2008

 Hi friendz,
i already posted Create Account and profile in sql server 2005 and  sent sql mail on trigger in sql server 2005 . 2day I'm showing sending mail through store procedure



code

ALTER PROCEDURE [dbo].[SP_Candidate_ReferAFriend_Email]
    @ToEmail varchar(200),
    @Msg varchar(MAX),
    @Subj varchar(200)
AS
BEGIN
    -- SENDING EMAIL
    BEGIN TRY
    EXEC msdb.dbo.sp_send_dbmail

    @recipients = @ToEmail,
    @body = @Msg,
    @sensitivity ='Personal',   
    @importance ='High',    
    @body_format = 'HTML',
    @subject = @Subj,
    @profile_name = 'Simplyasp'
    END TRY
    BEGIN CATCH
        SELECT
        ERROR_NUMBER() as ErrorNumber,
        ERROR_MESSAGE() as ErrorMessage;
    END CATCH   
END



for easy understanding i had given all parameter friendly name. i hope u can easily understand. :).
Have a nice day... 'N happy Coding :)

 Sex and the City: The Complete Second SeasonSex and the City 2: The Stories. The Fashion. The Adventure.Sex and the City - The Movie (Full Screen Edition)

Friday, July 30, 2010

sent sql mail on trigger in sql server 2005

 Hi frienz,
2day i'm sent an sql mail when somebody enter data to my table using trigger :)

 2 sent that u need to have a database mail profile( that i already posted how to create)
 To add trigger to a table
and add this code balance.documentation is on this code only


Create  trigger [tg_remainder] on [dbo].[Trans_Remainder]
AFTER INSERT -------- Intialize when trigger to happen
AS
        declare @id int, -------- primary key, from where i fetch the data
        @remainder nvarchar(MAX),-----Table field name
        @description nvarchar(MAX),------Table field name
        @MailBody  nvarchar(MAX),-------value from the database
        @TableHeader  nvarchar(MAX) ----------My html tag comes here

set @id=0
SET @remainder=''
SET    @description=''
SET @MailBody = ''
SET @TableHeader = '<html><body>
<table width="750" border="0">
  <tr>
    <td bgcolor="#990000">&nbsp;</td>
    <td bgcolor="#990000">&nbsp;</td>
  </tr>
  <tr>
    <td bgcolor="#CC99FF">&nbsp;</td>
    <td bgcolor="#CC99FF">&nbsp;</td>
  </tr>
  <tr>
    <td bgcolor="#FFCC99"><img src="http://evia.ucsd.edu/conferences/sdd/04/images/sdd2004_01.jpg" alt=""></img></td>
    <td bgcolor="#FFCC99">&nbsp;</td>
  </tr>'
select @id=Pk_Remainder from INSERTED---------- getting last inserted id here
declare Clu CURSOR----------Creating CURSOR
for
SELECT Str_Remainder,Str_Description from Trans_Remainder where Pk_Remainder=@id------------my query

OPEN Clu
FETCH NEXT from Clu INTO @remainder,@description

    IF(@@FETCH_STATUS=0)
    BEGIN

        SET @MailBody = @MailBody +  '<tr><td>'+getdate()+'</td></tr><tr><td>'+@description+'</td></tr>'                   
        FETCH NEXT FROM Clu INTO @remainder, @description
    END
    SET @MailBody = @TableHeader + @MailBody + '</table>'        
    -- SENDING EMAIL
    BEGIN TRY

    EXEC msdb.dbo.sp_send_dbmail
    @recipients = 'arun@simplyasp.net',
    @body = @MailBody,
    @sensitivity ='Personal',   
    @importance ='High',    
    @body_format = 'HTML',
    @subject = 'New Match Found ',
    @profile_name = 'GmailRemainder'--------- profile name
    END TRY

    BEGIN CATCH
        SELECT
        ERROR_NUMBER() as ErrorNumber,
        ERROR_MESSAGE() as ErrorMessage;
    END CATCH
close Clu
DEALLOCATE Clu


and i hope it's helped u... :)
 Have a nice day... 'N happy Coding :)

Illustrated C# 2008 (Windows.Net)Microsoft Visual C# 2010 Step by StepC# Essentials

Create Account and profile in sql server 2005

 Hi friends,
for sending mail from sql we need to have sql account and also Profile.Here is the steps to create that.let us use gmail as our mail server
Step 1:


 step 2:


Step 3:
Enter Profile name as demo_gmail  click add and create new account


 Step 4:
now create a mail account by 

Step 5:
This details are for gmail as a demo (remember if ur using third party mail server use 25 as port because most of them use that only)

Step 6:
 listing out all profile in the server

Step 7:
Step 8:
Configuring database mail if it ends successfully, Con-fig is done

Step 9:
Now lets sent a test mail 















Step 10:
select profile from the list
















Step 11:
enter your email id and send test mail 'n check ur email 














'n it's done

Hope it helped u
Have a nice day... 'N happy Coding :)

Microsoft SQL Server 2008 Management and AdministrationMCTS Self-Paced Training Kit (Exam 70-432): Microsoft SQL Server 2008-Implementation and Maintenance: Microsoft SQL Server 2008--Implementation and Maintenance (PRO-Certification)Microsoft SQL Server 2008 T-SQL Fundamentals (PRO-Developer)

Thursday, July 29, 2010

javascript asynchronous http way of coding in asp.net

 hi friendz,
if u want your database driven website to be fast u need to follow this way of structure.

Code on page1.aspx

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
   
    <script type="text/javascript">
        function sendReferAFriendEmail() {
              var ajaxRequest;  // The variable that makes Ajax possible!
               var isFound;

               try {
                   // Opera 8.0+, Firefox, Safari
                   ajaxRequest = new XMLHttpRequest();
               } catch (e) {
                   // Internet Explorer Browsers
                   try {
                       ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
                   } catch (e) {
                       try {
                           ajaxRequest = new
ActiveXObject("Microsoft.XMLHTTP");
                       } catch (e) {
                           // Something went wrong
                           alert("Your browser broke!");
                           return false;
                       }
                   }
               }
               // Create a function that will receive data sent from the server
               ajaxRequest.onreadystatechange = function () {
                   if (ajaxRequest.readyState == 4) {
                       alert(ajaxRequest.responseText);
                   }
                   else {

                   }
               }
               var sName =
document.getElementById("txt_1").value + "#" +
document.getElementById("txt_2").value + "#" +
document.getElementById("txt_3").value;

               var url = "page2.aspx?fe=" +sName;
               ajaxRequest.open("POST", url, true);
               ajaxRequest.send(null);
         
       }

    </script>
   
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table width="250" border="0">
  <tr>
    <td><input type="text" name="txt_1" id="txt_1" /></td>
    </tr>
  <tr>
    <td><input type="text" name="txt_2" id="txt_2" /></td>
    </tr>
  <tr>
    <td><input type="text" name="txt_3" id="txt_3" /></td>
    </tr>
  <tr>
    <td><input type="text" name="txt_4" id="txt_4" /></td>
    </tr>
  <tr>
    <td><input name="buton" id="buton" onclick="sendReferAFriendEmail();" type="submit" /></td>
    </tr>
</table>

    </div>
    </form>
</body>
</html>

 on page2.aspx catch data by query-string and save data.to pass a flag message  Response.Write("Done successfully");eliminate all the html tage on page two other wise  it show those on the message


Have a nice day... 'N happy Coding :)

Ajax: The Definitive GuideBuilding a Web Site with Ajax: Visual QuickProject GuideHead First Ajax 

Wednesday, July 28, 2010

Create backup of all database in sql server Query

 Hi friends,
It's simple to create backup of all database in the server 

SQl Query

DECLARE @name VARCHAR(50-- database name  DECLARE @path VARCHAR(256-- path for backup files  DECLARE @fileName VARCHAR(256) -- filename for backup 
DECLARE @fileDate VARCHAR(20-- used for file name
SET @path 'C:\Backup\' 
-- where i'm saving my back up

SELECT @fileDate CONVERT(VARCHAR(20),GETDATE(),112)
-- Fetching today's data
DECLARE db_cursor CURSOR FOR 
SELECT 
name FROM master.dbo.sysdatabases WHERE name NOT IN ('master','model','msdb','tempdb')
-- these database will be excluded

OPEN db_cursor   FETCH NEXT FROM db_cursor INTO @name  
WHILE @@FETCH_STATUS 0   BEGIN  
       SET 
@fileName @path + @name '_' @fileDate '.BAK'
-- file name comes here
       
BACKUP DATABASE @name TO DISK = @fileName 

       
FETCH NEXT FROM db_cursor INTO @name   END  

CLOSE 
db_cursor   DEALLOCATE db_cursor



Notes:
1.Create a folder with name Backup(whatever u giving in query) Otherwise it throw an error
2.Example of a backup file name:country_20100728.BAK
here Country_ is the database name and 20100728 means 2010-07-28 date when backup had created



Have a nice day... 'N happy Coding :)

Microsoft SQL Server 2008 Management and AdministrationMicrosoft SQL Server 2008 Internals (Pro - Developer)Beginning SQL Server 2008 for Developers: From Novice to Professional

Friday, July 23, 2010

Accessing Textbox (any asp.net ) Control on Edit Mode in Grid View

Hi friendz,
If you are working with GridView BoundField Columns and wanted to access the TextBox control on row editing for whatever reasons (which means when you click on the Edit link) then below is an example on how to do it.


Let say for example you need to change the BackColor of the TextBox on edit mode. So at  PreRender event of GridView, you can do something like this:

Code
protected void GridView1_PreRender(object sender, EventArgs e) {
                if (this.GridView1.EditIndex != -1) {
                    TextBox tb = (TextBox)GridView1.Rows[GridView1.EditIndex].Cells[1].Controls[0];
                    tb.BackColor = System.Drawing.Color.Blue;
                }
    }

 That's simple! I hope someone find this post useful!
Have a nice day... 'N happy Coding :)

ASP.NET Data Web Controls Kick StartProfessional DevExpress<sup><small>TM</small></sup> ASP.NET ControlsGridview, Style A, 12/bx