or
httpHandler.ProcessRequest(
HttpContext.Current);
method.
| protected void Page_Init(object sender, EventArgs e) |
| { |
| // Attach the parent grid's SelectedIndexChanged event |
| ParentGridPanel.ActiveGrid.SelectedIndexChanged += new EventHandler(ParentGrid_SelectedIndexChanged); |
| // Create the new GridButtonColumn to attach to the parent grid |
| GridButtonColumn GBC = new GridButtonColumn(); |
| GBC.CommandName = "Select"; |
| GBC.UniqueName = "Details"; |
| GBC.Text = "Details"; |
| // Attach the new column |
| this.ParentGridPanel.ActiveGrid.Columns.Add(GBC); |
| } |
| void ParentGrid_SelectedIndexChanged(object sender, EventArgs e) |
| { |
| RadGrid ParentGrid = (RadGrid)sender; |
| // Find the item selected by the user and get the value of the data key value field |
| object x = ParentGrid.SelectedItems[0].OwnerTableView.DataKeyValues[ParentGrid.SelectedItems[0].ItemIndex]["PRIMARY_KEY"]; |
| // Build the custom argument to send back to the main page |
| DrillDownEventArgs customArgs = new DrillDownEventArgs(); |
| customArgs.UniqueParentID = Int32.Parse(x.ToString()); |
| // Alert the main page that the user has clicked an item in the ParentGrid |
| if (DrillDownSelected != null) |
| { |
| this.DrillDownSelected(this, customArgs); |
| } |
| } |
| protected void Page_Load(object sender, EventArgs e) |
| { |
| if (Page.IsPostBack) |
| { |
| this.ParentGridPanel.ActiveGrid.Columns.RemoveAt(this.ParentGridPanel.ActiveGrid.Columns.Count - 1); |
| } |
| } |
| Imports System | |
| Imports System.Collections.Generic | |
| Imports System.ComponentModel | |
| Imports System.Data | |
| Imports System.IO | |
| Imports System.Net | |
| Imports System.Text | |
| Imports System.Web | |
| Imports System.Web.Services | |
| Imports System.Xml | |
| Imports System.Globalization | |
| <WebService([Namespace]:="http://www.telerik.com/"), WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _ | |
| Public Class StockQuoteService | |
| Inherits WebService | |
| Private random As Random | |
| Private yahooFeedTemplate As String = "http://finance.yahoo.com/d/quotes.csv?s={0}&f=nl1d1t1c1ohgv&e=.csv" | |
| Public Sub New() | |
| random = New Random(DateTime.Now.Millisecond) | |
| End Sub | |
| Property SessionQuotesData() As String | |
| Get | |
| Return HttpContext.Current.Session("TelerikAspAjaxGridApplication") | |
| End Get | |
| Set(ByVal value As String) | |
| HttpContext.Current.Session("TelerikAspAjaxGridApplication") = value | |
| End Set | |
| End Property | |
| <WebMethod(), Description("Gets stock quote for a specific symbol")> _ | |
| Public Function GetStockQuotes(ByVal stockTickers As String) As DataSet | |
| Dim stockTickerList As String() = stockTickers.Split(","c) | |
| Dim index As Integer | |
| For index = 0 To stockTickerList.Length - 1 | |
| stockTickerList(index) = stockTickerList(index).Trim() | |
| Next index | |
| Dim quotes As List(Of Quote) = New List(Of Quote) | |
| Dim url As String = String.Empty | |
| Dim webRequest As WebRequest = Nothing | |
| Dim webResponse As WebResponse = Nothing | |
| Dim stockTicker As String | |
| For Each stockTicker In stockTickerList | |
| url = String.Format(yahooFeedTemplate, HttpUtility.UrlEncode(stockTicker)) | |
| webRequest = HttpWebRequest.Create(url) | |
| webResponse = webRequest.GetResponse() | |
| Dim quote As Quote = GetQuoteData(webResponse.GetResponseStream()) | |
| quotes.Add(quote) | |
| Next stockTicker | |
| SerializeQuotesData(quotes) | |
| Dim dataset As New DataSet("QuotesDataSet") | |
| Dim data As XmlReader = XmlReader.Create(New System.IO.StringReader(SessionQuotesData)) | |
| dataset.ReadXml(data) | |
| Return dataset | |
| End Function | |
| Private Overloads Function GetQuote(ByVal bufferList() As String) As Quote | |
| Dim stockTicker As String = bufferList(0) | |
| Dim stockQuote As [Decimal] = [Decimal].Parse(bufferList(1), CultureInfo.InvariantCulture) | |
| Dim lastUpdated As DateTime = DateTime.Parse((bufferList(2) + " " + bufferList(3)), CultureInfo.InvariantCulture) | |
| Dim change As [Decimal] = [Decimal].Parse(bufferList(4), CultureInfo.InvariantCulture) | |
| Dim dailyMaxRange As [Decimal] = 0D | |
| If (bufferList(6) <> "N/A") Then | |
| dailyMaxRange = [Decimal].Parse(bufferList(6), CultureInfo.InvariantCulture) | |
| End If | |
| Dim dailyMinRange As [Decimal] = 0D | |
| If (bufferList(7) <> "N/A") Then | |
| dailyMinRange = [Decimal].Parse(bufferList(7), CultureInfo.InvariantCulture) | |
| End If | |
| Return New Quote(stockTicker, stockQuote, lastUpdated, change, dailyMinRange, dailyMaxRange) | |
| End Function | |
| Private Overloads Function GetQuote(ByVal quoteNode As XmlNode) As Quote | |
| Dim stockTicker As String = quoteNode.Attributes("stockTicker").Value | |
| Dim stockQuote As [Decimal] = [Decimal].Parse(quoteNode.Attributes("lastTrade").Value, CultureInfo.InvariantCulture) | |
| Dim lastUpdated As DateTime = DateTime.Parse(quoteNode.Attributes("lastUpdated").Value, CultureInfo.InvariantCulture) | |
| Dim change As [Decimal] = [Decimal].Parse(quoteNode.Attributes("change").Value, CultureInfo.InvariantCulture) | |
| Dim dailyMaxRange As [Decimal] = IIf(quoteNode.Attributes("dailyMaxRange").Value = "N/A", 0D, [Decimal].Parse(quoteNode.Attributes("dailyMaxRange").Value, CultureInfo.InvariantCulture)) | |
| Dim dailyMinRange As [Decimal] = IIf(quoteNode.Attributes("dailyMinRange").Value = "N/A", 0D, [Decimal].Parse(quoteNode.Attributes("dailyMinRange").Value, CultureInfo.InvariantCulture)) | |
| Return New Quote(stockTicker, stockQuote, lastUpdated, change, dailyMinRange, dailyMaxRange) | |
| End Function | |
| Private Function GetQuoteData(ByVal dataStream As Stream) As Quote | |
| Dim buffer As String = Nothing | |
| Dim sr As New StreamReader(dataStream) | |
| Try | |
| buffer = sr.ReadToEnd() | |
| Finally | |
| sr.Dispose() | |
| End Try | |
| buffer = buffer.Replace("""", "") | |
| buffer = buffer.Replace(ControlChars.Cr + ControlChars.Lf, "") | |
| Dim bufferList As String() = buffer.Split(New Char() {","c}) | |
| Dim quote As Quote = GetQuote(bufferList) | |
| Return quote | |
| End Function | |
| Private Function GetQuotesData(ByVal xmlData As String) As List(Of Quote) | |
| Dim xmlDocument As New XmlDocument() | |
| xmlDocument.LoadXml(xmlData) | |
| Dim quotes As List(Of Quote) = New List(Of Quote) | |
| Dim quote As Quote = Nothing | |
| Dim quoteNode As XmlNode | |
| For Each quoteNode In xmlDocument.DocumentElement.ChildNodes | |
| quote = GetQuote(quoteNode) | |
| quotes.Add(quote) | |
| Next quoteNode | |
| Return quotes | |
| End Function | |
| Private Sub SerializeQuotesData(ByVal quotes As List(Of Quote)) | |
| Dim str As StringBuilder = New StringBuilder("<quotes>") | |
| Try | |
| Dim quote As Quote | |
| For Each quote In quotes | |
| str.Append("<quote ") | |
| str.Append("stockTicker=""" & quote.StockTicker & """ ") | |
| str.Append("lastTrade=""" & quote.StockQuote.ToString(CultureInfo.InvariantCulture) & """ ") | |
| str.Append("change=""" & quote.Change.ToString(CultureInfo.InvariantCulture) & """ ") | |
| str.Append("lastUpdated=""" & quote.LastUpdated.ToString("MM/dd/yyyy HH:mm:ss") & """ ") | |
| str.Append("dailyMaxRange=""" & quote.DailyMaxRange.ToString(CultureInfo.InvariantCulture) & """ ") | |
| str.Append("dailyMinRange=""" & quote.DailyMinRange.ToString(CultureInfo.InvariantCulture) & """ ") | |
| str.Append(" />") | |
| Next quote | |
| Catch e As Exception | |
| End Try | |
| str.Append("</quotes>") | |
| SessionQuotesData = str.ToString() | |
| End Sub | |
| End Class |
Hi,
I am trying to export the Grid details to Word/Excel/PDFformat files. I am able to accomplish the same. I would like to add Title,Headers and footers to the exported data.
When I open the exported file I should see the Titles andthen Data.
For example..
Title: sometitle
Subject: somesubject
From: dateTo: date
Grid data
.
.
.
.
Report for To –From days
Thanks
Sabarish