Tuesday, November 27, 2007

RDLC + Page is blank + Vista

Today I ran into an issue with the report viewer control and the rendering of some RDLC reports. If I ran the application user localhost then the report would render correctly. As soon as I change from it from localhost to my computer name (http://mycomputer/report.aspx) the report control would show but the report itself would render as blank.

After hours of playing around with IIS and searching google the answer was to change the application to use the classic.asp Application pool and also set impersonation to true.

Hope this helps someone out in the future!

Monday, November 26, 2007

Update Web.config + Asp.net VB.net

Ever needed to update the web.config dynamically?

Make sure you add a reference at the top of the page to

Imports System.Web.Configuration


Dim value As String = "mskilton@gmail.com"

Dim config As Configuration =
webConfigurationManager.OpenWebConfiguration("~")
Dim appsetting As AppSettingsSection =
config.GetSection("appSettings")

appsetting.Settings("emailaddress").Value = value

config.Save()


Have fun updating your web.config programmatically!

Saturday, November 24, 2007

Blogger + ASP.net Code

Okay two posts in one day you guys are pretty lucky. After writing my first post I couldn't seem to get my asp.net code to post correctly. Using this tool http://www.manoli.net/csharpformat/
was just the ticket!

Exporting Gridview to Excel - With Checkbox

I often get the same questions asked of my while working with asp.net. If these examples seem to simplistic then please move along :)

Exporting a gridview to excel is pretty simple, there are plently of examples on the net, however not to many when it comes to only selecting certain rows to export.

an example Gridview and button


<asp:GridView ID="dg_disp" runat="server" AutoGenerateColumns="False" DataKeyNames="id" DataSourceID="SqlDataSource1" >
<Columns>
<asp:TemplateField><ItemTemplate><asp:CheckBox ID="cbSelect" runat="server" /></ItemTemplate></asp:TemplateField>
<asp:BoundField DataField="id" />
<asp:BoundField DataField="member" />
</Columns>
</asp:GridView>

<asp:button id="Button1" runat="server" />

---Code Behind---



Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button1.Click

' Set the content type to Excel
Response.ContentType = "application/vnd.ms-excel"

'Turn off the view state
Me.EnableViewState = False

'Remove the charset from the Content-Type header
Response.Charset = String.Empty

Dim myTextWriter As New System.IO.StringWriter()
Dim myHtmlTextWriter As New System.Web.UI.HtmlTextWriter(myTextWriter)
Dim colCount As Integer = dg_disp.Columns.Count
Dim counter As Integer = 0

'loop through all rows in the gridview
For Each row As GridViewRow In dg_disp.Rows

'skip header footers rows etc
If row.RowType = DataControlRowType.DataRow Then

'find the checkbox in the template field
Dim i As CheckBox = row.FindControl("cbSelect")

If i.Checked = True Then
While counter <> colCount

'don't output checkbox field change if checkbox is in different place
If counter <> 0 Then
Response.Write(row.Cells(counter).Text & vbTab)
End If

counter = counter + 1
End While
Response.Write(vbCr)
counter = 0
End If
End If

Next


'Write the HTML to the browser
Response.Write(myTextWriter.ToString())

'End the response
Response.End()

End Sub