Thursday, December 23, 2010

What is the DataField Name of a GridView bound to a String Array?

This is a special case that I don’t remember experiencing before but resolved with the help of a StackOverflow question Binding an ASP.NET GridView Control to a string array.

In a simple Asp.Net Membership management application I was simply binding a Role list to a GridView so I could click a link to see which users were members of a selected Role. I was using the following syntax in the CodeBehind where grvRoles is the GridView:

grvRoles.DataSource = Roles.GetAllRoles
grvRoles.DataBind()

Note: Roles.GetAllRoles() is in the System.Web.Security namespace which returns a string array of Roles from the aspnetdb Membership Database.


On the Designer:



<asp:GridView ID="grvRoles" runat="server" 
    EnableModelValidation="True">
    <Columns>
        <asp:CommandField ShowSelectButton="True" />
    </Columns>
</asp:GridView>

Which produced the following output with the GridView auto-generated columns. Notice the column name is “Item”, but imagethe datasource is a string array which doesn’t technically have a DataField name like if it was bound to a Generic List or Collection of class objects.


I want to use a LinkButton where the CommandArgument is the Role name which is represented as a String value of the array. So If I convert the “Select” Command button column to a Template field, what do I use as the DataField name? Generally I would use the syntax:



<asp:GridView ID="GridView1" runat="server" 
    EnableModelValidation="True">
    <Columns>
    <asp:TemplateField ShowHeader="False">
        <ItemTemplate>
            <asp:LinkButton ID="lnkMembers" 
                runat="server" CausesValidation="False"
                CommandArgument='<%#Eval("Item") %>' 
                CommandName="Select" Text="Members"></asp:LinkButton>
        </ItemTemplate>
    </asp:TemplateField>
</Columns>
</asp:GridView>

 

Note the CommandArgument=’<%#Eval(“Item”) %>’, but that won’t work, because the String Array doesn’t actually have an Item property. Instead you can use the longhand syntax: CommandArgument='<%# container.dataitem %>'.

 

If I don’t want to have the GridView auto-generate the columns, what do I use for the asp:BoundField name? Apparently there is a secret syntax by using an exclamation point <asp:BoundField DataField="!" HeaderText="Role" />.

The breakpoint will not currently be hit. No symbols have been loaded for this document.

Five foot bug art in Las Vegas Bellagio's conservatoryDoug Butscher’s blog post about the subject was able to get me debugging again in one of the Visual Studio 2010 projects in my solution. As he noted in Step 3, the Modules window indicated that the Symbols were loaded.

I stopped the debugger, deleted only the obj folder, and restarted the IDE. That was enough to fix it for me.

Tuesday, December 21, 2010

Vista Backup Stopped Working - Fix

Backup for the BackupI’ve been using Windows Vista’s built-in Backup and Restore functionality daily for over three years now, with good success until recently. I recently started experiencing a backup error every day for the incremental backups as well as when I attempt to create a new full backup.

The backup did not complete successfully. The file or directory is corrupted and unreadable (0x80070570)

This error message was not very helpful because it didn’t indicate which file or directory was corrupt. It also didn’t indicate whether it was my backup source Operating System partition, Files partition, or the backup destination device.

The Fix

I ran numerous utilities including the Seagate Tools (manufacturer of the source and destination hard drives) on both drives which didn’t detect any problems. The final fix was opening a Command Prompt and running “CHKDSK C: /R” where the C-drive was my primary OS disk. Because the Operating System was in use, the Check Disk utility couldn’t run until the next restart.

Backup Redundancy

The Complete PC Backup, where it creates a VHD image file of each of the backup drives, was working the entire time which provided some level of comfort while troubleshooting the traditional backup process.

photo credit: ground.zero / CC BY 2.0

Monday, December 20, 2010

Visual Studio Cloud Service for Azure Development Requires IIS7

View above the clouds over NevadaLately I am really wondering about the utility of using the Visual Studio built-in web server for development. Last month it was causing inconsistent rendering of AJAX modal popups, this month installing the Visual Studio Cloud Service for Windows Azure development requires IIS7.

Having the built-in web server seemed like a way to minimize the system resources and attack surface of the development workstation, but it doesn’t seem as practical anymore.