Saturday, 7 July 2018

Import/Export data from/to Excel using ASP.NET

Step 1: (Designing)
Default.aspx
1)Set dropdownlist property of Age(AppendDataBoundItems->true and AutoPostBack->true)
2) Set textbox4 Property(TextMode-> MultiLine) .


Note: Display Age values from  1 to 100 using dropdownlist
 DropDownList1.DataSource = Enumerable.Range(1, 100);

 DropDownList1.DataBind();


Step 2: Add coding  
Default.aspx.cs
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.IO;

namespace Project
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DropDownList1.DataSource = Enumerable.Range(1, 100);
            DropDownList1.DataBind();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
          
             string path = @"C:\Users\iiht\output.csv";
             string delimiter = ",";
            if(!File.Exists(path))
            {
               string createText = "Column 1 Name" + delimiter + "Column 2 Name" + delimiter + "Column 3 Name" + delimiter +"column 4 Name"+ Environment.NewLine;
                File.WriteAllText(path, createText);
            }

            // This text is always added, making the file longer over time
            // if it is not deleted.
            string appendText = TextBox1.Text + delimiter + TextBox2.Text+ delimiter + TextBox3.Text + delimiter + DropDownList1.SelectedValue + Environment.NewLine;
            File.AppendAllText(path, appendText);

            // Open the file to read from.
            string readText = File.ReadAllText(path);
            Console.WriteLine(readText);
            TextBox1.Text = "";
            TextBox2.Text = "";
            TextBox3.Text = "";
        
        }

        protected void Button2_Click(object sender, EventArgs e)
        {

            string path = @"C:\Users\iiht\output.csv";
            string delimiter = ",";
            string appendText = TextBox1.Text + delimiter + TextBox2.Text + delimiter + TextBox3.Text + delimiter + DropDownList1.SelectedItem.Value + Environment.NewLine ;
            File.AppendAllText(path, appendText);

            // Open the file to read from.
            string readText = File.ReadAllText(path);
           
            TextBox4.Text = readText;
           
        }
    }
}
    Step 3: Run the application
Step 4:
Step 5:
    

1 comment:

  1. Python is an open-source, high level, interpreted programming language which offers great opportunities for object-oriented programming. Choosing a python training program from Red Prism Group, which is best training institute for python in noida.

    ReplyDelete

Global Infrastructure and its components in AWS

You may operate your workloads wherever and however you choose with the AWS Global Infrastructure, and you'll use the same network, cont...