Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GridView dates using textboxes 1

Status
Not open for further replies.

Cpreston

MIS
Mar 4, 2015
972
GB
Hi

I have a gridview that as one text box with a button. When I run it and add in a date and click the button it works fine. This brings in the data bound Date_submitted field for that specific date.

I want to add on another text box and enter a date from and date to and then click the button (if the button is needed) and it then returns the rows with dates from the Date_submitted field.

I can add in the textbox ok but when I run it just brings in the dates from the first textbox entered.

I have tried to change the code to some examples I found, but then the code gets corrupt and I end up back to square one.

Could someone help me add on another textbox and get it working please, a simple step by step guide perhaps. I am fairly new to asp net gridviews so going into the coding is a little problematic for me.

Thanks
 
you do NOT need to create a datasource...
in your web config, create a connection string to your database with all the credentials needed (see: Click on the type of database you have and it will show you how to format your connection string...look up how to add a connection string to your web.config

in your page you use that connection string when you build your command object... then execute your sp and convert to a datatable and bind to your grid
 
Hi

Well I have progressed and now have the dates from the stored procedure and button working (may not be perfect but working)

My next step is to try and export into Excel. I found a good video on you tube and looked fairly good until trying. The problem is the savefileialogue1 which is the issue, all of them are red underlined.
If I hover over them it says the name saveFileDialog1 does not exist in the current context. In the video before adding in the code he went to the toolbox and into Dialogs and went onto SaveFileDialog but that's all. In my menu system this is greyed out (all under Dialogs is). So any ideas please anyone. Thanks

}
protected void Button1_Click(object sender, EventArgs e)
{
saveFileDialog1.InitialDirectory = "C:";
saveFileDialog1.Title = "Save as Excel File";
saveFileDialog11.FileName = "";
saveFileDialog1.Filter = "Excel Files(2003) │*.xls│Excel Files(2007)│*.xls";
}
 
Hi

Yes that's good and I have found a lot of other code, being I am inexperienced with the coding I am finding it very hard that fits into the code below the button click that works.

I am spending hours on trying code that obviously will never work. I take a closer look at your link,

Thanks
 
Hi

No couldn't apply it far top complicated, I carry on the search for something a little less complicated and linked to a button for export and save as.

Thanks for all your help
 
There is nothing complicated about it. You don't have to implement it the exact same way.
The key code here is in the export function:
Code:
 Response.Clear();
    Response.Buffer = true;
    Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.xls");
    Response.Charset = "";
    Response.ContentType = "application/vnd.ms-excel";

.. get data and bind grid ... you already know how to do this

... The next block of code, he is just looping through the cells and formatting the color.. you don't have to do this

.. then  you just need this to finish up
   //style to format numbers to string
        string style = @"<style> .textmode { } </style>";  //this just formats long numbers so they don't show in Excel as exponential notation
        Response.Write(style);
        Response.Output.Write(sw.ToString());
        Response.Flush();
        Response.End();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top