Export to Excel from a Repeater?

前端 未结 3 1940
执念已碎
执念已碎 2021-01-05 12:37

Right now I am using this to export a repeater (with multiple nested repeaters) to excel:

protected void ExportToExcel(object sender, EventArgs e) 
{     
Re         


        
3条回答
  •  轮回少年
    2021-01-05 13:16

    not to answer your question directly, but given you my opinion

    for that kinda of data, is in my opinion that you should use a GridView control, taking your example you will need to write something like:

    
        
            
            
            
    Header Type Name Date Amount
    <%#Eval("Header")%> <%#Eval("Type")%> <%#Eval("Name")%> <%#Eval("Date", "{0:d}")%> <%#Eval("Value", "{0:c}")%>

    using a GridView all ou nee dto write in the HTML part is only:

    
        
            
            
            
            
            
        
    
    

    something simpler and easier to read

    you will have much more control using a GridView object rather than a Repeater, and, you will never have that kinda of problems, because rendering the gridView will always came with the table tags.

    Hope it helps

    And BTW, I tested your case and i did not got any problems even if I was not writting the tags like Spencer mention.

    to see my code: File with HTML and Method - File with myObject

提交回复
热议问题