I would like to execure createCSV when the user select the row from the gridview. I am not sure how I can capture the contract id and psss it to the procedure.please help. thank you
Code:
<asp:BoundField DataField="lettingdate" HeaderText="Letting Date" >
<HeaderStyle Wrap="False" Font-Bold="True" />
<ItemStyle Wrap="False" Font-Bold="True" ForeColor="#FF3300" />
</asp:BoundField>
<asp:TemplateField HeaderText="View Abstract (PDF)">
<ItemTemplate>
<asp:HyperLink ID="abstractPDF" runat="server" Target="_blank" Text='<%# Eval("contractid","Abstract (PDF)") %>' > </asp:HyperLink>
</ItemTemplate>
<HeaderStyle Wrap="False" />
<ItemStyle Wrap="False" />
</asp:TemplateField>
<asp:TemplateField HeaderText="View Abstract (CSV)">
<ItemTemplate>
<asp:HyperLink ID="abstractCSV" runat="server" Text='<%# Bind("contractid","Abstract (CSV)" )%>' ></asp:HyperLink>
</ItemTemplate>
<HeaderStyle Wrap="False" />
<ItemStyle Wrap="False" />
</asp:TemplateField>
Code:
sub createCSV()
' Dim contractId As String = "090024"
'Dim contractId As String = Request.QueryString("contractId")
oOracleConn.Open()
Dim drlettingDetails As OracleDataReader
Dim i As Integer = 0
Dim cmdlettingDetails As OracleCommand = New OracleCommand
cmdlettingDetails.Connection = oOracleConn
cmdlettingDetails.CommandType = CommandType.Text
With cmdlettingDetails
.Connection = oOracleConn
.CommandText = "ex_letting_Detail"
.CommandType = CommandType.StoredProcedure
.Parameters.Clear()
End With
cmdlettingDetails.Parameters.Add(New OracleParameter("p_contract", OracleDbType.Varchar2)).Value = contractId
cmdlettingDetails.Parameters.Add(New OracleParameter("p_result", OracleDbType.RefCursor)).Direction = ParameterDirection.Output
drlettingDetails = cmdlettingDetails.ExecuteReader()
'For field name
For i = 0 To drlettingDetails.FieldCount - 1
If i < (drlettingDetails.FieldCount - 1) Then
sb.Append(Chr(34) & drlettingDetails.GetName(i) & Chr(34) & ",")
Else
sb.Append(Chr(34) & drlettingDetails.GetName(i) & Chr(34) & vbCrLf)
End If
Next
'For field value
While drlettingDetails.Read()
For i = 0 To drlettingDetails.FieldCount - 1
If i < (drlettingDetails.FieldCount - 1) Then
sb.Append(Chr(34) & drlettingDetails.GetValue(i).ToString.Replace(Chr(34), Chr(34) & Chr(34)) & Chr(34) & ",")
Else
sb.Append(Chr(34) & drlettingDetails.GetValue(i).ToString & Chr(34) & vbCrLf & vbCrLf)
End If
Next
End While
Dim drbidderItemPrice As OracleDataReader
Dim j As Integer = 0
Dim cmdbidderItemPrice As OracleCommand = New OracleCommand()
cmdbidderItemPrice.Connection = oOracleConn
cmdbidderItemPrice.CommandType = CommandType.Text
With cmdbidderItemPrice
.Connection = oOracleConn
.CommandText = "ex_bid_items_price_quote"
.CommandType = CommandType.StoredProcedure
.Parameters.Clear()
End With
cmdbidderItemPrice.Parameters.Add(New OracleParameter("p_contract", OracleDbType.Varchar2)).Value = contractId
cmdbidderItemPrice.Parameters.Add(New OracleParameter("p_result", OracleDbType.RefCursor)).Direction = ParameterDirection.Output
drbidderItemPrice = cmdbidderItemPrice.ExecuteReader()
'For field name
For j = 0 To drbidderItemPrice.FieldCount - 1
If j < (drbidderItemPrice.FieldCount - 1) Then
sb.Append(Chr(34) & drbidderItemPrice.GetName(j) & Chr(34) & ",")
Else
sb.Append(Chr(34) & drbidderItemPrice.GetName(j) & Chr(34) & vbCrLf)
End If
Next
'For field value
While drbidderItemPrice.Read()
For j = 0 To drbidderItemPrice.FieldCount - 1
If j < (drbidderItemPrice.FieldCount - 1) Then
sb.Append(Chr(34) & drbidderItemPrice.GetValue(j).ToString.Replace(Chr(34), Chr(34) & Chr(34)) & Chr(34) & ",")
Else
sb.Append(Chr(34) & drbidderItemPrice.GetValue(j).ToString & Chr(34) & vbCrLf)
End If
Next
End While
sb.Append(vbCrLf)
Dim drbidderVendorName As OracleDataReader
Dim k As Integer = 0
Dim cmdbidderVendorName As OracleCommand = New OracleCommand()
cmdbidderVendorName.Connection = oOracleConn
cmdbidderVendorName.CommandType = CommandType.Text
With cmdbidderVendorName
.Connection = oOracleConn
.CommandText = "ex_bidders_Company_Name"
.CommandType = CommandType.StoredProcedure
.Parameters.Clear()
End With
cmdbidderVendorName.Parameters.Add(New OracleParameter("p_contract", OracleDbType.Varchar2)).Value = contractId
cmdbidderVendorName.Parameters.Add(New OracleParameter("p_result", OracleDbType.RefCursor)).Direction = ParameterDirection.Output
drbidderVendorName = cmdbidderVendorName.ExecuteReader()
'For field name
For k = 0 To drbidderVendorName.FieldCount - 1
If k < (drbidderVendorName.FieldCount - 1) Then
sb.Append(Chr(34) & drbidderVendorName.GetName(k) & Chr(34) & ",")
Else
sb.Append(Chr(34) & drbidderVendorName.GetName(k) & Chr(34) & vbCrLf)
End If
Next
'For field value
While drbidderVendorName.Read()
For k = 0 To drbidderVendorName.FieldCount - 1
If k < (drbidderVendorName.FieldCount - 1) Then
sb.Append(Chr(34) & drbidderVendorName.GetValue(k).ToString.Replace(Chr(34), Chr(34) & Chr(34)) & Chr(34) & ",")
Else
sb.Append(Chr(34) & drbidderVendorName.GetValue(k).ToString & Chr(34) & vbCrLf)
End If
Next
End While
Dim filename As String
filename = "Selected contract id:" & contractId & ".CSV"
Response.ContentType = "Application/x-csv"
Response.AddHeader("content-disposition", "attachment;filename=""" & filename & """")
Response.Write(sb.ToString)
Response.End()
oOracleConn.Close()
End Sub