Dynamic Nested ASP.Net GridView using AJAX, Webservices and jQuery


I haven’t blogged for a while, I have been really swamped at work.

Anyway last week I after using jQuery for a while (for those who don’t know jQuery is awesome, take the time to try it) I had a brilliant idea. After numerous previous attempts at building nested ASP.Net GridViews I thought hang on a minute, once a gridview has been rendered it is normal HTML. Thus its a table with rows(<tr>) and columns(<td>), so all I need to do is somehow get a empty row after every row to act as a place holder(<div></div>) for the nested grid.


I did a couple of Google searches and found weird and wonderful ways to implement the empty rows but most of them were far to complex for what I needed. Then I found a post (sorry I cant remember the source) with the following code for the RowDataBound event:

Protected Sub GridView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
  If e.Row.RowType = DataControlRowType.DataRow ThenRead More »

ASP.Net ERROR: The remote server returned an error: (401) Unauthorized. RESOLVED

I struggled with this error(The remote server returned an error: (401) Unauthorized.) for 2 weeks.

Here is my setup:
IIS with integrated Authentication.
There is no user login thus the user name and password isn’t getting stored.

Finally after grabbing bit and pieces of the Internet my error has been resolved. Here is my solution:

String path = templateData.getField(TemplateData.FieldName.LOGO);
System.Net.WebRequest objRequest = System.Net.WebRequest.Create(path);
objRequest.UseDefaultCredentials = true;
objRequest.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
System.Net.WebResponse objResponse = objRequest.GetResponse();
System.IO.Stream  strm = objResponse.GetResponseStream();
System.IO.StreamReader rdr = new System.IO.StreamReader(strm);
Image logoImage = Image.GetInstance(strm);

Hope this helps someone

ASP.Net: Textarea carriage returns in IE and Firefox

Today I came across a problem with carriage returns in a textarea and came up with a solution.

Basically what’s happening is we are generating a PDF with an address in it that the user has the option of using the one supplied by the database or if it doesn’t exist then the user enters the address in a text area.

The address might be something like

119 Farringdon Road
United Kingdom

Now we had the following code:

address =  address.Replace(Environment.NewLine, "\n")

This string then gets passed to the PDF generator.

Now when you submit this from IE it works fine but when you submit from Firefox the address ends up like this

119 Farringdon RoadLondonEC1R 3DAUnited Kingdom


address  = address.Replace(Chr(13), "\n").Replace(Chr(10), "\n")
address =  address.Replace("\n\n", "\n")

The first line replaces chr(13) and chr(10) with “\n” as it seems that IE and firefox uses different carrige return characters. When I tested this in IE the address ended up with double carriage returns. Thus the reason for the second line which finds “\n\n” and replaces it with “\n”

Hope this helps somebody