I have two buttons and textbox , Whenever user enters the id in the textbox and press enter datais displayed in the gridview and we have an other button in the screen and that button is to get the gridview data in json string.
i have user export to excel its working fine but requirement is to get it in json string
This is what i have did for excel
//protected void btnJson_Click(object sender, EventArgs e)
//{
// string JsonQuery = "select p.Name , i.Item , i.Date from Item I Join Product p on p.id = i.id where p.Number = @no";
// List<string> lstIDs = this.hdnCsvVal.Value.Split(new char[]
// {
// ','
// }).ToList<string>();
// string csv = string.Empty;
// StringBuilder sb = new StringBuilder();
// foreach(var item in lstIDs)
// {
// sb.Append(item + ",");
// }
// using (OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Temp\Data.mdb"))
// {
// conn.Open();
// OleDbCommand cmd = new OleDbCommand(JsonQuery,conn);
// cmd.CommandType = CommandType.Text;
// cmd.Parameters.AddWithValue("No", TxtSearch.Text);
// var dt = new DataTable();
// dt.Load(cmd.ExecuteReader());
// csv = ToCsv(dt);
// Response.Clear();
// Response.Buffer = true;
// Response.AddHeader("content-disposition", "attachment;filename=Details.csv");
// Response.Charset = "";
// Response.ContentType = "application/text";
// Response.Output.Write(csv);
// Response.Flush();
// Response.End();
// }
//}
please help how to convert the gridview data to json string..