Click here to Skip to main content
15,923,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai friends,

I have a "incident.aspx" web page.In this page we are adding Title,IncidentNumber,Priority,Starttime,endtime,status in the textbox and calendar controls respectively.If I click on button control I want to display Excel report that display the rows based on the entered incident number.Plz help me.

<table border="3" cellpadding="3" cellspacing="3" style="width:60%" align="center">
  <tr>
  <td align="right">
     <asp:Label ID="lblTitle" runat="server" Text="Title"></asp:Label>
  </td>
  <td>
  <asp:TextBox ID="txtTitle" runat="Server"  ></asp:TextBox>
  </td>
  </tr>
<tr>
                <td align="right">
                  
                    <asp:Label ID="lblIncidentNumber" runat="server" Text=" Incident Number :"></asp:Label>
                   
                </td>
                <td>
                    <asp:TextBox ID="txtIncidentNumber" runat="Server" onkeypress="return isNumberKey(event)" ></asp:TextBox>

                </td>
             
            </tr>


<tr>

<td align="right" >
  <asp:Label ID="lblPriority" runat="server" Text="Priority"></asp:Label>
</td>
<td>
  
   
    <asp:DropDownList ID="ddlPriority" runat="server" AutoPostBack="True">
        <asp:ListItem>P0</asp:ListItem>
        <asp:ListItem>P1</asp:ListItem>
        <asp:ListItem>P2</asp:ListItem>
        <asp:ListItem>P3</asp:ListItem>
        <asp:ListItem>P4</asp:ListItem>
    </asp:DropDownList>


</td>
</tr>
<tr>

<td  align="right">
                  
                  <asp:Label ID="lblStarttime" runat="server" Text=" Start time"></asp:Label>
</td>
<td>

                    
   
    
                     <asp:Calendar ID="StartCalendar" runat="server" 
                         ></asp:Calendar>
                     
                   
                     
                    
</td>
</tr>



 <tr>
                <td align="right">
                 
                  <asp:Label ID="lblEndtime" runat="server" Text="End time"></asp:Label>
                </td>
                <td>
                                  
                     <asp:Calendar ID="EndCalendar" runat="server" 
                         ></asp:Calendar>
                     
                </td>
               
            </tr>
            
         
                 <tr>
                <td align="right">
                 
                  
                  <asp:Label ID="lblStatus" runat="server" Text="Status"></asp:Label>
                     </td>
                <td>
                    <asp:TextBox ID="txtStatus" runat="Server"></asp:TextBox>
           
                     </td>
               
            </tr>
            <tr>
            <td align="right">
                 </td>
            <td>
                 </td>
            </tr>
            
                
          
                 <tr>
                <td align="right">
                  
                     </td>
                <td>
                     </td>
               
            </tr>
            <tr>
            <td align="right">
                 </td>
            <td>
                 </td>
            </tr>
            
               <tr>
                <td align="right">
                  
                     </td>
                <td>
                  
                      </td>
               
            </tr>
            
               <tr>
                <td align="right">
                 
                     </td>
                <td>
                     </td>
               
            </tr>
      
             
        
               <tr>
                <td align="right">
              
                     </td>
                <td>
                     </td>
               
            </tr>
       
               
           
               

 <tr>

<td align="center" colspan="2">
                    <asp:Button ID="Button2" runat="server" Text="Submit" 
         OnClientClick="return validate()" style="height: 26px"  />


</td>

</tr>
<tr>

<td  align="right" colspan="2">
     </td></tr><tr>

<td  align="right" colspan="2">
     </td></tr></table>


Thanks in advance
Posted

1 solution

You can try this


DataSet ds = new DataSet();
ds = BindGrid();
dtaFinal.DataSource = ds.Tables["batches"];
dtaFinal.DataBind();
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
dtaFinal.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900