Button Control

Discussion in 'ASP .Net Web Controls' started by JMehta, Nov 30, 2008.

  1. JMehta

    JMehta Guest

    Hi,
    I am relatively new at .net applications and am having trouble doing the
    following. I have tried to read the help and discussion groups but cannot
    seem to be able to do what is required.

    I have a Master Page and a content page. On the content page I have:
    1) a gridview (GridView1) with 4 fields
    Name
    Date
    AreaCode
    PhoneNumber
    2) Button1 (Upload)
    3) Button2 (Save)
    4) Button3 (Select)

    I also have an excel spreadsheet with 4 columns (same as the gridview columns)

    When the user clicks Button1 (Upload), I would like to have the contents of
    the excel spreadsheet show on the GridView1.

    When the user clicks on Button2 (Save), I would like to add the data from
    the gridview to an SQL database table (NameInfo), I would like the gridview
    to be blank after the save and a message saying "data added". If the number
    of records added can be displayed in the message that would be great.

    When the user clicks on Button3 (Select), I would like to show all the
    records from the SQL database table (NameInfo).

    Any help would be much appreciated.
     
    JMehta, Nov 30, 2008
    #1
    1. Advertisements

  2. What exactly is it that you are unable to do? You never mentioned a specific
    problem in your posting. But I think my first question is what code are you
    using to get the data from/save the data to the Excel file? Also, is your
    problem really with one of the Button controls, or is the problem with
    something else? You need to give more details and specifics about what you
    really need help with.
     
    Nathan Sokalski, Nov 30, 2008
    #2
    1. Advertisements

  3. JMehta

    JMehta Guest

    I would like to know how to:
    1) import an excel spreadsheet to a gridview based on a button click;
    2) how do I initiate saving data from a gridview to a database based on a
    button click;
    3) how do I initiate a select to the gridview from a database initiated by a
    button click.

    --
    Thanks for your help.

    J Mehta


     
    JMehta, Dec 1, 2008
    #3
  4. When you say "based on a button click" and "initiated by a button click", do
    you mean triggered by the Button.Click event? As for importing an excel
    spreadsheet, you will either need to find some free (or not free) .NET class
    that takes the data from an excel file and stores it in a .NET Collection or
    Array of some type. Since Excel files are not simple text files that you can
    simply read the way you might read an xml or csv file, the first step there
    is finding a way to make the data available to your application. Saving the
    data from the gridview to a database should be pretty simple and basic if
    you have ever worked with databases and GridViews in ASP.NET, you will need
    to be more specific about where your problem is for that. Initiating a
    Select statement to display new data in the GridView should be nothing more
    than a simple PostBack. Once again, you will need to be more specific about
    where your problem is. Please provide us with more details on where your
    problems are, and it may also help to show us what you currently have and
    what, if any, errors you are recieving. Good Luck!
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

     
    Nathan Sokalski, Dec 2, 2008
    #4
  5. JMehta

    JMehta Guest

    So how would I import a csv file to a gridview based on a button.click event?
     
    JMehta, Dec 2, 2008
    #5
  6. In the Button.Click event handler, read in the data from a *.csv file using
    a StreamReader. You will need to parse the data and store it in a variable
    of a type that you can use as a datasource for your GridView.
     
    Nathan Sokalski, Dec 2, 2008
    #6
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.