Saturday, September 24, 2011

count selected items of checkboxlist and also separate it with comma

A simple way to count only selected items of checkboxlist

 var totalcount = CheckBoxList1.Items.Cast<ListItem>().Where(item => item.Selected).Count();


now If you want separte it with comma then



 foreach (ListItem selectedItem in CheckBoxList1.Items)
        {
            if (selectedItem.Selected)
            {


                if (string.IsNullOrEmpty(selectedExch))


                    selectedExch = selectedItem.Value;


                else


                    selectedExch = selectedExch + "," + selectedItem.Value;


            }


        }


Saturday, August 27, 2011

insert data from one table to another in sql


Helo guys.. A simple way to insert data from one table to another



Insert into Table1(distcentre, distcode,disttname) select distributorcenter, UserCode,Name
from Table2

Saturday, August 6, 2011

Trigger Tutorial


                                                                 TRigger :--
Trigger is like stored Procedure.It is used after Insert update delete or Before it.The difference between both is that trigger has relation with tables while stored procedure not.
Suppose we have two tables ‘test’ and ‘test22’. Now I wants that when a new record is inserting  in the table test then after insert a trigger automatically  and pick the last inserted record  from test and insert the same into test22 table.. Here we go
Step I --  Create Trigger

Create trigger   myfirst <-----(Trigger Name)
on test  <-----------(Table name on which we are applying)
after insert
as
begin
declare @idss as int, @nameb as nvarchar(50),@cls as nvarchar(50)
select @idss=id,@nameb=name1,@cls=class from test where id= (select isnull(max(id),0) from test)
insert into test22 values(@idss,@nameb,@cls)
end


Step II --  Now when you insert a record in test then automatically the same record will insert in ‘test22’

Any problem plz mail me at  goldyabk1@gmail.com.. 
I am trying to do best to update my blog.



Tuesday, February 15, 2011

how to convert bytes in kb,mb and gb in fileupload

take a button,fileupload and a label in designingtime

protected void Button1_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
            string format = System.DateTime.Now.ToLongDateString() +","+ System.DateTime.Now.ToLongTimeString();

            int size = FileUpload1.FileBytes.Length;
            Label1.Text = FormatBytes(size);

       
        }

      
    }

public string FormatBytes(int Bytes)
    {
        string filesize;
        if (Bytes >= 1073741824)
        {
            decimal size = decimal.Divide(Bytes, 1073741824);
            filesize = string.Format("{0:##.##} GB", size);
        }
        else if (Bytes >= 1048576)
        {
            decimal size = decimal.Divide(Bytes, 1048576);
            filesize = string.Format("{0:##.##} MB", size);
        }
        else if (Bytes >= 1024)
        {
            decimal size = decimal.Divide(Bytes, 1024);
            filesize = string.Format("{0:##.##} KB", size);
        }
        else if (Bytes > 0 & Bytes < 1024)
        {
            decimal size = Bytes;
            filesize = string.Format("{0:##.##} Bytes", size);
        }
        else
        {
            filesize = "0 Bytes";
        }
        return filesize;
    }


You have to add in web.configuration also--

<system.web>
        <httpRuntime  maxRequestLength="2097151" executionTimeout="360"/>
</system.web>







Monday, December 20, 2010

payment through paypal in Asp.Net

A simple Way to payment through Paypal..
For this it is compulsory to login in your pay pal account.



Now come to the coding part ..  Take one text-box and a button

 protected void Button1_Click(object sender, EventArgs e)
    {
       protected decimal dec;(take this globally)
        try
        {
            dec = Convert.ToDecimal(TextBox1.Text);
                       
        }

        catch(Exception ex)
        {
            Label1.Visible = true;
        }
        paypalquery();
    }


 protected void paypalquery()
    {

//Make a class named it as "paypal"
        paypal pay = new paypal();
        pay.AccountEmail = paypal.Email;
        pay.PayPalBaseUrl = paypal.PayPalUrl;
        pay.Amount = dec;
        pay.ItemName = "New Item Added";

        pay.SuccessUrl = Request.Url + "?paypal=success";
        pay.CancelUrl = Request.Url + "?paypal=cancel";

        Response.Redirect(pay.submiturl());

        return;


    }



this is cs class

public class paypal
{


    public string LogoUrl = "";
    public string AccountEmail = "";
    public string BuyerEmail = "";
    public string SuccessUrl = "";
    public string CancelUrl = "";
    public string ItemName = "";
    public decimal Amount = 0.00M;
    public string InvoiceNo = "";


    public static string Email = "PayPalEmailAccount@YourCompany.com";
    public static string PayPalUrl = "https://www.sandbox.paypal.com/us/cgi-bin/webscr?";

    public string PayPalBaseUrl = "https://www.paypal.com/cgi-bin/webscr?";


public paypal()
{
//
// TODO: Add constructor logic here
//
}

    public string submiturl()
    {
        StringBuilder buil = new StringBuilder();

        buil.Append(PayPalBaseUrl + "cmd=_xclick&business=" + HttpUtility.UrlEncode(AccountEmail));

       if (Amount != null)
           buil.AppendFormat("&amount={0:f2}", Amount);

       if (ItemName != null && ItemName != "")
           buil.AppendFormat("&item_name={0}", HttpUtility.UrlEncode(ItemName));

       if (SuccessUrl != null && SuccessUrl != "")
           buil.AppendFormat("&return={0}", HttpUtility.UrlEncode(SuccessUrl));

       if (CancelUrl != null && CancelUrl != "")
           buil.AppendFormat("&cancel_return={0}", HttpUtility.UrlEncode(CancelUrl));

        return buil.ToString();
    }


    public class configuration
    {
        public static string email = "PayPalEmailAccount@YourCompany.com";
        public static string PayPalUrl = "https://www.sandbox.paypal.com/us/cgi-bin/webscr?";
    }


}