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

    Fetch the data and show it the data in word using asp.net c#

    I use select query, I need to show the data in word document after clicking the button.
  • #762318
    Hi

    You can try this select Query in Sql side using wildcard



    Select * from tblEmplist where name like '%john%'
    Select * from tblEmplist where name like '%john'
    Select * from tblEmplist where name like 'john%'


    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #762325
    Hi

    You can try this code



    RegNo <asp:TextBox ID="TxtRegno" runat="server"></asp:TextBox>
    Name <asp:TextBox ID="TxtNameEntry" runat="server" OnTextChanged="TxtNameEntry_TextChanged"></asp:TextBox>
    Address <asp:TextBox ID="TxtAddress" runat="server"></asp:TextBox>

    <asp:GridView ID="Grd1" runat="server">
    </asp:GridView>



    Server side c# code



    protected void TxtNameEntry_TextChanged(object sender, EventArgs e)
    {
    DataTable dt = new DataTable();
    // If you need all fields means use this
    //SqlDataAdapter sqladp = new SqlDataAdapter("Select * from tblEmplist where name like '%" + TxtNameEntry.Text + "%'", con);

    // If you need Particular fields means use this
    SqlDataAdapter sqladp = new SqlDataAdapter("Select regno from tblEmplist where name like '%" + TxtNameEntry.Text + "%'", con);
    sqladp.Fill(dt);
    Grd1.DataSource=dt;
    Grd1.DataBind();

    }


    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #762331
    Hi selvi,

    As per my understand the post, your need is to export data into word format, if this is your requirement you can Google it the same, so that you can understand how to export data into word, pdf etc...

    This is the sample link for your reference.

    https://www.google.co.in/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=how%20to%20export%20gridview%20to%20word%20in%20asp.net

    Before asking question you just try out by your own by searching in Google, so that you can understand how to overcome the issues.

    Hope you understood..

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #762349
    hi naveensanagasetti i search and try my self i got the result thats y i post the question i got the outtput like this
    the gridview data are not shown in the excel

    my code

    protected void btnExportExcel_Click(object sender, EventArgs e)
    {
    Response.Clear();
    Response.Buffer = true;

    Response.AddHeader("content-disposition",
    "attachment;filename=GridViewExport.xls");
    Response.Charset = "";
    Response.ContentType = "application/vnd.ms-excel";
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);

    GridView1.AllowPaging = false;
    GridView1.DataBind();

    //Change the Header Row back to white color
    // GridView1.HeaderRow.Style.Add("background-color", "white");

    //Apply style to Individual Cells
    // GridView1.HeaderRow.Cells[0].Style.Add("background-color", "white");
    // GridView1.HeaderRow.Cells[1].Style.Add("background-color", "white");
    // GridView1.HeaderRow.Cells[2].Style.Add("background-color", "white");
    //GridView1.HeaderRow.Cells[3].Style.Add("background-color", "white");

    for (int i = 0; i < GridView1.Rows.Count;i++ )
    {
    GridViewRow row = GridView1.Rows[i];

    //Change Color back to white
    // row.BackColor = System.Drawing.Color.White;

    //Apply text style to each Row
    row.Attributes.Add("class", "textmode");

    //Apply style to Individual Cells of Alternating Row
    if (i % 2 != 0)
    {
    // row.Cells[0].Style.Add("background-color", "white");
    // row.Cells[1].Style.Add("background-color", "white");
    ///row.Cells[2].Style.Add("background-color", "white");
    //row.Cells[3].Style.Add("background-color", "white");
    }
    }
    GridView1.RenderControl(hw);

    //style to format numbers to string
    string style = @"<style> .textmode { mso-number-format:\@; } </style>";
    Response.Write(style);
    Response.Output.Write(sw.ToString());
    Response.Flush();
    Response.End();
    }

    mymistake.bmp

    Delete Attachment

  • #762350
    hi kumar i need it in MSword

  • #762353

    Hi

    You can try this code for convert word from gridview

    Client Side


    RegNo <asp:TextBox ID="TxtRegno" runat="server"></asp:TextBox>
    Name <asp:TextBox ID="TxtNameEntry" runat="server" OnTextChanged="TxtNameEntry_TextChanged" AutoPostBack="true"></asp:TextBox>
    Address <asp:TextBox ID="TxtAddress" runat="server"></asp:TextBox>

    <asp:GridView ID="Grd1" runat="server" AutoGenerateColumns="false">
    <Columns>
    <asp:BoundField DataField="regno" HeaderText="Regno" />
    <asp:BoundField DataField="name" HeaderText="Name" />
    <asp:BoundField DataField="adress" HeaderText="Address" />
    </Columns>
    </asp:GridView>

    <asp:Button ID="bt1" runat="server" Text="Word" OnClick="bt1_Click" />


    Server Side C# Code


    protected void TxtNameEntry_TextChanged(object sender, EventArgs e)
    {
    DataTable dt = new DataTable();
    // If you need all fields means use this
    SqlDataAdapter sqladp = new SqlDataAdapter("Select * from tblEmplist where name like '%" + TxtNameEntry.Text + "%'", con);
    // If you need Particular fields means use this
    //SqlDataAdapter sqladp = new SqlDataAdapter("Select regno from tblEmplist where name like '%" + TxtNameEntry.Text + "%'", con);
    sqladp.Fill(dt);
    Grd1.DataSource = dt;
    Grd1.DataBind();
    }

    protected void bt1_Click(object sender, EventArgs e)
    {
    Response.Clear();
    Response.Buffer = true;
    Response.AddHeader("content-disposition",
    "attachment;filename=Test1.doc");
    Response.Charset = "";
    Response.ContentType = "application/vnd.ms-word ";
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    Grd1.RenderControl(hw);
    Response.Output.Write(sw.ToString());
    Response.Flush();
    Response.End();
    }
    public override void VerifyRenderingInServerForm(Control control)
    {
    /* Verifies that the control is rendered */
    }



    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #762354
    Hi

    I have attache Snapshots given below

    for gridview to word.

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

    Delete Attachment

  • #762357
    Hi Selvi,

    I request you to debug the code and check why it is not reading data..?

    Whether it's throwing any error..?
    whether data is loaded perfectly or not..?

    Check it by putting break point and let me know.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #762368
    Hi

    If you need excel means try this code for export excel


    protected void bt1_Click(object sender, EventArgs e)
    {
    Response.Clear();
    Response.Buffer = true;

    Response.AddHeader("content-disposition",
    "attachment;filename=Test1.xls");
    Response.Charset = "";

    Response.ContentType = "application/vnd.ms-excel ";
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    Grd1.RenderControl(hw);
    Response.Output.Write(sw.ToString());
    Response.Flush();
    Response.End();
    }
    public override void VerifyRenderingInServerForm(Control control)
    {
    /* Verifies that the control is rendered */
    }

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #762369
    Hi

    Client Side


    RegNo <asp:TextBox ID="TxtRegno" runat="server"></asp:TextBox>
    Name <asp:TextBox ID="TxtNameEntry" runat="server" OnTextChanged="TxtNameEntry_TextChanged" AutoPostBack="true"></asp:TextBox>
    Address <asp:TextBox ID="TxtAddress" runat="server"></asp:TextBox>

    <asp:GridView ID="Grd1" runat="server" AutoGenerateColumns="false">
    <Columns>
    <asp:BoundField DataField="regno" HeaderText="Regno" />
    <asp:BoundField DataField="name" HeaderText="Name" />
    <asp:BoundField DataField="adress" HeaderText="Address" />
    </Columns>
    </asp:GridView>

    <asp:Button ID="bt1" runat="server" Text="Word" OnClick="bt1_Click" />


    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.


Sign In to post your comments