I am able to save excel sheet from GridView perfectly. However, I need to add one custom column, which will be URL of a file on sever, I am not allowed to add URLs directly in the table (as per company's development policies). What is the best way to achieve this? I tried pulling URL from web.config however I am not sure where to add that in the following code
<asp:GridView ID="bestpractgrv" runat="server" AutoGenerateColumns="False" CellPadding="3" GridLines="Vertical" Width="100%" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" PageSize="10" AllowPaging="True" OnPageIndexChanging="OnPaging" DataKeyNames="iID">
<AlternatingRowStyle BackColor="Gainsboro" />
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chkboxSelectAll" runat="server" onclick="CheckAllEmp(this);" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Discipline" Visible="false">
<ItemTemplate>
<asp:Label ID="iid" runat="server" Text='<%# Bind("ID")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Discipline">
<ItemTemplate>
<asp:Label ID="discplnlbl" runat="server" Text='<%# Bind("cDiscipline")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
VB CODE
Private Sub ExportFunction()
SaveCheckedValues()
Response.Clear()
Response.Buffer = True
Response.Charset = ""
Response.ContentType = ContentType
Dim sw As New StringWriter()
Dim hw As New HtmlTextWriter(sw)
bestpractgrv.AllowPaging = True
BindDataGrid()
bestpractgrv.HeaderRow.Style.Add("background-color", "#FFFFFF")
bestpractgrv.HeaderRow.Cells(0).Visible = False
For i As Integer = 0 To bestpractgrv.HeaderRow.Cells.Count - 1
bestpractgrv.HeaderRow.Cells(i).Style.Add("background-color", "#df5015")
bestpractgrv.HeaderRow.Cells(i).Style.Add("color", "#FFFFFF")
Next
If ViewState("CHECKED_ITEMS") IsNot Nothing Then
Dim CheckBoxArray As ArrayList = DirectCast(ViewState("CHECKED_ITEMS"), ArrayList)
Dim rowIdx As Integer = 0
'Dim pdfloc As String
For i As Integer = 0 To bestpractgrv.Rows.Count - 1
Dim row As GridViewRow = bestpractgrv.Rows(i)
row.Visible = False
Dim index As Integer = CInt(bestpractgrv.DataKeys(row.RowIndex).Value)
If CheckBoxArray.Contains(index) Then
row.Visible = True
row.Cells(0).Visible = False
End If
Next
End If
bestpractgrv.RenderControl(hw)
Dim rgrvw As String
Dim idate As Date = DateAndTime.Now
Dim filedate As String
Dim fileloc As String
Dim fpath As String
Dim filename As String
Dim htparam As New Hashtable
Dim mode As String = "insert"
'fpath = "C:\excelbooks\"
fpath = Server.MapPath("~/Excelbooks/")
filename = "bestpractices"
filedate = idate.Month & idate.Day & idate.Hour & idate.Millisecond
rgrvw = sw.ToString()
fileloc = fpath + filename + filedate + ".xls"
System.IO.File.WriteAllText(fileloc, rgrvw) '<-- excel file is generated and copied in specified folder
htparam.Add("@date", idate)
htparam.Add("@location", fileloc)
htparam.Add("@mode", mode)
Dim ds As New DataSet
ds = Customdll.Functions.AppExecuteSelectDataset(CommandType.StoredProcedure, "STORED_PROCEDURE", , htparam)
End Sub