Friday, September 28, 2018

Checkbox List

 protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        int i;
        for (i = 0; i < CheckBoxList1.Items.Count; i++)
        {

            if (CheckBoxList1.SelectedIndex == i)
            {



                TextBox1.Text += CheckBoxList1.Items[i].Text;


            }
            else
            {
         


            }


        }


    }

Break Back Button on browser

<head>
<script type = "text/javascript" >

        function preventBack() { window.history.forward(); }

        setTimeout("preventBack()", 0);

        window.onunload = function () { null };

</script>
</head>

Convert PDF

DOWNLOAD :  itextsharp.dll



using System;
using System.Web;
using System.Web.UI;
using System.Data;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html.simpleparser;



 public override void VerifyRenderingInServerForm(Control control)
    {
        /* Verifies that the control is rendered */
    }
    protected void btnPDF_Click(object sender, EventArgs e)
    {
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=UserDetails.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        this.Page.RenderControl(hw);
        StringReader sr = new StringReader(sw.ToString());
        Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0.0f);
        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();
        htmlparser.Parse(sr);
        pdfDoc.Close();
        Response.Write(pdfDoc);
        Response.End();
    }

Expiry Limit Coading

 protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text = DateTime.Now.Day.ToString()+"/"+DateTime.Now.Month.ToString()+"/"+DateTime.Now.Year.ToString();
     //   Label2.Text = ;
       // Label3.Text = ;
        if (Label1.Text == "12/2/2012")
        {
            Response.Write("Please renew your account");
        }
        else if (Label1.Text=="13/2/2012")
        {
            Response.Write("Your account is expire");
        }
    }

GRIDVIEW Footer Concept


Set  grideviw  property
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

BackColor="White" BorderColor="#336699" BorderStyle="Solid" BorderWidth="1px"

CellPadding="2" Font-Names="Verdana" ShowFooter="true" Font-Size="10pt"

Width="50%" DataKeyNames="id1" GridLines="Horizontal"

onrowdatabound="GridView1_RowDataBound">

 <Columns>

<asp:BoundField DataField="id1" HeaderText="ino" />

<asp:TemplateField HeaderText="total">

<ItemTemplate>

 <asp:Label ID="lblPrice" runat="server" Text='<%# Eval("total")%>' />

 </ItemTemplate>

 <FooterTemplate>
 <asp:Label ID="lblTotalPrice" runat="server" />
 </FooterTemplate>                 
 </asp:TemplateField>

</Columns>










C# code  :


private void BindData()
{
       
        string cs = @"connection string";
        cn = new SqlConnection(cs);
        cn.Open();

        string k = "select * from invoicetbl";

        SqlDataAdapter da = new SqlDataAdapter(k,cn);

        DataTable table = new DataTable();
      
        da.Fill(table);

        GridView1.DataSource = table;
        GridView1.DataBind();
}

  decimal totalPrice = 0M;
  decimal totalStock = 0M;
  int totalItems = 0;


protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {


        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lblPrice = (Label)e.Row.FindControl("lblPrice");

            Label lblUnitsInStock = (Label)e.Row.FindControl("lblUnitsInStock");

            decimal price = Decimal.Parse(lblPrice.Text);

            totalPrice += price;


            totalItems += 1;
        }

        if (e.Row.RowType == DataControlRowType.Footer)
        {
            Label lblTotalPrice = (Label)e.Row.FindControl("lblTotalPrice");
          

            lblTotalPrice.Text = totalPrice.ToString();         

         
        }
    }

Thursday, September 27, 2018

Create Multiple Popup In AJAX

  <asp:LinkButton ID="lblfake" runat="server" Text=""></asp:LinkButton>

    <cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" PopupControlID="Panel1" TargetControlID="lblfake" BackgroundCssClass="modalBackground" BehaviorID="addAttribute1"></cc1:ModalPopupExtender>
            

<asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" Style="display: none;Width: 600px">


                       // Create Panel 1


                       // create Panel 2



</panel>




         panelupdate.Visible = false;
        panelauthor.Visible = true;

Wednesday, September 26, 2018

Remove Last Character from String in C#, VB.NET with Example

protected void Page_Load(object sender, EventArgs e)
{
string istr = "1,2,3,4,5,6,7,8,9,10,";
string ostr = istr.Remove(istr.Length - 1, 1);
Response.Write(ostr);
}




protected void Page_Load(object sender, EventArgs e)
{
string istr = "1,2,3,4,5,6,7,8,9,10,";
string ostr = istr.Trim(",".ToCharArray());
Response.Write(ostr);
}



protected void Page_Load(object sender, EventArgs e)
{
string istr = "aspdotnet-code.com,";
string ostr = istr.Remove(istr.IndexOf(","));
Response.Write(ostr);
}

Gridview Checkbox

 protected void Button1_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow grow in GridView1.Rows)
        {
            //Searching CheckBox("chkDel") in an individual row of Grid  
            CheckBox chkdel = (CheckBox)grow.FindControl("ch");
            //If CheckBox is checked than delete the record with particular empid  
            if (chkdel.Checked)
            {
                int id = Convert.ToInt32(grow.Cells[0].Text);
                DeleteRecord(id);
            }
        }

Convert Table to Word Document

<div id="divExport" runat="server"> 

      <table >

       //developed format as  your requirement

     </table>


</div>


<button click   event>

{

            Response.AddHeader("content-disposition", "attachment;filename=letter6month.doc");
            Response.Charset = "";
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.ContentType = "application/doc";
            System.IO.StringWriter stringWrite = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
            divExport.RenderControl(htmlWrite);
            Response.Write(stringWrite.ToString());
            Response.End();


}




Sunday, September 23, 2018

Create Live Connection String Under Web.config file

Open web.config File 

<configuration>
  <system.web>


  </system.web>


 <connectionStrings>
    <add name="key" connectionString="Data Source=ip/doamin;
         Network Library=DBMSSOCN;
         Connection Timeout=15;
         Packet Size=4096;
         Integrated Security=no;
         Initial Catalog=databasename;
         User ID=userid;
         password=password;
         Encrypt=no;
         Max Pool Size=50000;" />
  </connectionStrings>

</configuration>


How to Access inside Aspx Page 



using System.Data.SqlClient;
using System.Configuration;


 string cs = ConfigurationManager.ConnectionStrings["keyname"].ToString();
        cn = new SqlConnection(cs);
        cn.Open();





Tuesday, September 18, 2018

How to increase Upload time in File Upload Control

<system.web>


       

  <!--  <httpRuntime maxRequestLength="104857600" executionTimeout="3600" />-->

or



<httpRuntime

executionTimeout="904857600"

maxRequestLength="104857600"

useFullyQualifiedRedirectUrl="false"

minFreeThreads="8"

minLocalRequestFreeThreads="4"

appRequestQueueLimit="100"

enableVersionHeader="true"/>


    
  </system.web>

Sunday, September 16, 2018

Simple virus creatation

Open Notepad and write "start" without quotes


Start
Start
Start


and then save it with .bat extension.


Now double click on this .bat file to run Command Prompt

Exception Handling i


 Exception Handlin
An exception is a problem that arises during the execution of a program. A C# exception is a response to an exceptional circumstance that arises while a program is running, such as an attempt to divide by zero.
Exceptions provide a way to transfer control from one part of a program to another. C# exception handling is built upon four keywords: try, catch, finally, and throw.
·        try: A try block identifies a block of code for which particular exceptions is activated. It is followed by one or more catch blocks.
·        catch: A program catches an exception with an exception handler at the place in a program where you want to handle the problem. The catch keyword indicates the catching of an exception.
·        finally: The finally block is used to execute a given set of statements, whether an exception is thrown or not thrown. For example, if you open a file, it must be closed whether an exception is raised or not.
·        throw: A program throws an exception when a problem shows up. This is done using a throw keyword.
·         try
·         {
·            // statements causing exception
·         }
·         catch( ExceptionName e1 )
·         {
·            // error handling code
·         }
·         catch( ExceptionName e2 )
·         {
·            // error handling code
·         }
·         catch( ExceptionName eN )
·         {
·            // error handling code
·         }
·         finally
·         {
·            // statements to be executed
·         }

Exception Classes in C#
C# exceptions are represented by classes. The exception classes in C# are mainly directly or indirectly derived from the System.Exception class. Some of the exception classes derived from the System.Exception class are the System.ApplicationException and System.SystemException classes.
The System.ApplicationException class supports exceptions generated by application programs. Hence the exceptions defined by the programmers should derive from this class.
The System.SystemException class is the base class for all predefined system exception.
The following table provides some of the predefined exception classes derived from the Sytem.SystemException class:
Exception Class
Description
System.IO.IOException
Handles I/O errors.
System.IndexOutOfRangeException
Handles errors generated when a method refers to an array index out of range.
System.ArrayTypeMismatchException
Handles errors generated when type is mismatched with the array type.
System.NullReferenceException
Handles errors generated from deferencing a null object.
System.DivideByZeroException
Handles errors generated from dividing a dividend with zero.
System.InvalidCastException
Handles errors generated during typecasting.
System.OutOfMemoryException
Handles errors generated from insufficient free memory.
System.StackOverflowException
Handles errors generated from stack overflow.

using System;
namespace ErrorHandlingApplication
{
   class DivNumbers
   {
      int result;
      DivNumbers()
      {
         result = 0;
      }
      public void division(int num1, int num2)
      {
         try
         {
            result = num1 / num2;
         }
         catch (DivideByZeroException e)
         {
            Console.WriteLine("Exception caught: {0}", e);
         }
         finally
         {
            Console.WriteLine("Result: {0}", result);
         }
      }
      static void Main(string[] args)
      {
         DivNumbers d = new DivNumbers();
         d.division(25, 0);
         Console.ReadKey();
      }
   }
}
When the above code is compiled and executed, it produces the following result:
Exception caught: System.DivideByZeroException: Attempted to divide by zero. 
at ...
Result: 0


Throws
public class ThrowTest2
    {
 
        static int GetNumber(int index)
        {
            int[] nums = { 300, 600, 900 };
            if (index > nums.Length)
            {
                throw new IndexOutOfRangeException();
            }
            return nums[index];
 
        }
        static void Main() 
        {
            int result = GetNumber(3);
            
        }
    }
    /*
        Output:
        The System.IndexOutOfRangeException exception occurs.
    */


GRIDVIEW ON ROW DATA BOUND EVENT

 Database Create  Student : roll , name , city , cost  Fix 6 Value  in Database Record  ====================================================...