You must Sign In to post a response.
  • Category: HTML

    Export search results

    Hi,
    i have used search query to display the data in front end , iam trying to export the search results data to excel file . export button will be displayed along with search results but the entire table data is exporting but unable to export the search results data can any one explain about it with a sample example
  • #754051
    Hi,

    we are doing the export to excel code in our project:

    so like that u can use according such as:
    protected void ExportExcel()
    {
    string items = "";
    DataSet ds = new DataSet();
    int[] indexes = this.lstCustomer.GetSelectedIndices();
    if (indexes.Length > 0)
    {
    for (int index = 0; index < indexes.Length; index++)
    {
    items += this.lstCustomer.Items[indexes[index]].Value + ",";
    }

    }
    else
    {
    items = string.Empty;
    }
    Int32 len;
    len = items.Length;
    if (items.Length > 0)
    {
    items = items.Substring(0, len - 1);
    }


    ds = obj.Get_Mail_Alerts(hdnUserId.Value.ToString(), items, string.Empty);

    string[] allColumns = { "scorpclm_name", "scorpclm_StartDate", "scorpclm_ContractEffectiveDate", "scorpclm_ContractExpiryDate", "CustomerName", "username", "EmailType", "scorpclm_EmailSentOn", "scorpclm_Acknowledgement", "scorpclm_AcknowledgementDate", "scorpclm_completedStatus", "scorpclm_CompletedDate" };
    string[] allCaptions = { "Contract Name", "Contract start date", "Contract effective date", "Contract expired date", "Customer Name", "Owner Name", "Context", "Email Sent On", "Acknowledgement", "Acknowledged Date", "Completed Status", "Completed Date" };

    Response.AddHeader("Content-Disposition", "attachment; filename=MailAlert.xls");
    Response.ContentType = "application/vnd.msexcel";
    Response.Write("<TABLE BORDER='0' CELLPADDING='2' CELLSPACING='0' width='100%'>");
    Response.Write("<tr>");
    Response.Write("<h3><center>Mail Alerts</center></h3></td>");
    Response.Write("</tr>");
    Response.Write("</TABLE>");
    Response.Write("<br />");
    Response.Write("<TABLE BORDER='1' CELLPADDING='2' CELLSPACING='2' width='100%'>");
    Response.Write("<tr>");
    for (int i = 0; i < alCaptions.Length; i++)
    {
    Response.Write("<td width='20%'>");
    Response.Write("<b>" + alCaptions[i] + "</b>");
    Response.Write("</td>");
    }
    Response.Write("</tr>");
    foreach (DataRow dr in ds.Tables[0].Rows)
    {
    Response.Write("<tr>");
    for (int i = 0; i < alColumns.Length; i++)
    {
    Response.Write("<td>");
    Response.Write(dr[alColumns[i]]);
    Response.Write("</td>");
    }
    Response.Write("</tr>");
    }
    Response.Write("</TABLE>");
    Response.End();
    }


    Regards,
    Chitaranjan Mallick
    +919894730854
    mallickchitaranjan@gmail.com

  • #754071
    Hi,

    It is very easy to do that,
    You can export data from datatable or dataset.
    You can export data from gridview, or you can bind data to rdlc or crystal report and then you can export it in needed format.
    There are thousands of resources available for that.
    If you want to export all data then fill datatable with all data with out any search condition and if you want to export filtered results data then you can fill datatable in that manner
    and then you can export data into excel from datatable very easily.
    You should try ro explore more by your self for "How to export data into excel from datatable in c#"

    I hope you got my point, if still you have an issue than i'll get back to you.

    Regards,
    Nirav Prabtani (Senior Web Developer)
    Email : niravjprabtani@gmail.com
    blog : niravprabtani.blogspot.in

  • #754103
    Hi Bhaskar,

    Please try below snippet. Here, data are exporting to excel from datagridview.

    private void btnExport_Click(object sender, EventArgs e)
    {
    if (dgvSearchCourier.Rows.Count > 0)
    {
    Microsoft.Office.Interop.Excel.ApplicationClass XcelApp = new Microsoft.Office.Interop.Excel.ApplicationClass();

    XcelApp.Application.Workbooks.Add(Type.Missing);

    for (int i = 1; i < dgvSearchCourier.Columns.Count + 1; i++)
    {
    XcelApp.Cells[1, i] = dgvSearchCourier.Columns[i - 1].HeaderText;
    }

    for (int i = 0; i < dgvSearchCourier.Rows.Count - 1; i++)
    {
    for (int j = 0; j < dgvSearchCourier.Columns.Count; j++)
    {
    XcelApp.Cells[i + 2, j + 1] = dgvSearchCourier.Rows[i].Cells[j].Value.ToString();
    }
    }
    XcelApp.Columns.AutoFit();
    XcelApp.Visible = true;
    }
    }

    Hope it will he helpful to you.

    Thanks,
    Ram Prasad

  • #754125
    Hi ,
    i have a search-box with submit button it will display the search results but i want i to add checkbox to that text box so that when we click on check box the search -boxx with submit button has to be displayed can any one give me some sample code for that one


  • Sign In to post your comments