Portal XP Blog Site
DJ's Personal Blog

News

Custom Gridview

So I have been needing a custom gridview that has a bunch of features that aren't included in the default view.  So I have found a bunch of different articles on the subject and many have some features I want but not all of them so I took about 5 different people's work and put them together in one big custom gridview control.

So you can download the custom grid view file here.  (Rename the .txt to .cs)  Just drop the file into your app_code directory and you are set to use it.  Then in your page at the top you add:

<%@ Register TagPrefix="cc1" Namespace="HWControls" %>

And then your gridview is this:

<asp:UpdatePanel ID="up1" runat="server">
    <ContentTemplate>
    <cc1:HWGridView runat="server" id="MyGridView" autogeneratecolumns="False" datasourceid="MySource" 
        BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px"
        CellPadding="4" ForeColor="Black" GridLines="Vertical" Width="100%"
        AllowSorting="true" allowpaging="True" PageSize="26" ShowWhenEmpty="True"
        DefaultSortExpression="compName" DefaultSortDirection="Ascending">
        <RowStyle BackColor="#F7F7DE" Font-Size="10px" />
        <Columns> 
            <asp:TemplateField ItemStyle-Width="25px">
                <ItemTemplate>
                <img src="/includes/images/cAccountsImage.png" style="border: 0px;" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="compName" HeaderText="Account Name " SortExpression="compName" />
            <asp:TemplateField ItemStyle-Width="125px" HeaderText="Primary Contact">
                <ItemTemplate>
                <%# DataBinder.Eval(Container.DataItem, "fname")%> <%# DataBinder.Eval(Container.DataItem, "lname") %>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="PhoneNum" HeaderText="Phone Number" ItemStyle-Width="125px" />
            <asp:TemplateField ItemStyle-Width="125px" HeaderText="Owner">
                <ItemTemplate>
                <%# DataBinder.Eval(Container.DataItem, "firstname")%> <%# DataBinder.Eval(Container.DataItem, "lastname") %>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="compStatus" HeaderText="Status" SortExpression="compStatus" ItemStyle-Width="90px" />
        </Columns> 
        <FooterStyle BackColor="#CCCC99" />
        <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
        <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="White" />
        <EmptyDataTemplate>No records found</EmptyDataTemplate>
    </cc1:HWGridView>
    </ContentTemplate>
</asp:UpdatePanel>

Lose the UpdatePanel if you don't have the ASP.NET Ajax controls.  So what does the above do that isn't included in the default gridview?

  • Image when sorting columns.  So you get a little arrow up and down.
  • Filtering.  So if you put a blank at the end of a headertext like "Account Name ".  This creates a filter text box that allows you to type anything in a text box and filters the content of the gridview.
  • Default Sort.  You can set a default sort value and direction.
  • Paging: You get the page numbers at the bottom, ability to jump to a certain page and total results on the top of the page.

The only thing I really want is to freeze the top row with something that works with browsers more then just IE.  I'll post a screen shot for everyone so you can see it.  Also, I need to grab the links to the places where I found this code and what I did to make it better.

Inserting row into a data table

So I ran into what I think is a somewhat interesting problem tonight.  I had the need to insert a row into an established datatable.  Now I have seen similar problems and even used the old and handy newrow().  However what I needed was the ability to set the inserted row into the first position.  I figured it would be easy but it took some digging on my part to find the command I needed.  However, here it is for those who might need it later (like me!).

DataRow newRow = dsDrop.Tables["tblClubPages"].NewRow();
newRow["pagesID"] = DataBinder.Eval(e.Item.DataItem, "pagesID").ToString();
newRow["pagesName"] = DataBinder.Eval(e.Item.DataItem, "pagesName").ToString();
newRow["pagesAccess"] = DataBinder.Eval(e.Item.DataItem, "pagesAccess").ToString();
newRow["pagesAccessGroup"] = DataBinder.Eval(e.Item.DataItem, "pagesAccessGroup").ToString();
tblClubPages.Rows.InsertAt(newRow, 0);

Like I said, nothing shocking in terms of use but very handy to be able to specify the location.

First Blog Post

So I have tried to create blog's in the past and have never really done a good job of keeping up on the blog.  But this time its going to be different.  So what should everyone expect on this blog?  There are a bunch of things that happen in my life that should be interesting to some people on this wondering planet.  So here is the small list of items you should see posts about.  No particular order:

My Family - There will be some posts about my wondering wife Sarah, children Bethany and Connor.

Microsoft - I happen to work at Convergent Solutions Group, who is a Microsoft Gold Partner where we specialize in Microsoft Unified Communications.  So we do a ton of work with Microsoft, UM and phone integration.  We also do a great deal of Novell to Microsoft "flips".  I am a MCP and nearing finishing my MCSE.

VMware - Simply the best virtualization software that exists right now.  If you are not familiar with VMware and you are in IT you have been living under a rock.  Being a VCP (VMware Certified Professional) I deal with some crazy VMware stuff on a daily basis but love everything this product can do.

GCM - Its a little company I started with a friend that focuses on building great web-based tools for golf leagues and clubs.  We are trying to expand what we do.  Everything you are reading on this blog for instance was created in our flagship product Web Manager.

Golf - I love to play golf.  Most likely not a bunch of stuff to post about it but I will here and there.

Debate - In my free time I coach debate at Robbinsdale Cooper High School.  Over the past couple of years we have been incredibly successful at local and national tournaments.  Later this June I'll be flying to Las Vegas for the 2008 National Debate Tournament.

So if you like something on the site let me know.  If you have a question feel free to post it.  I'm going to make sure that I post on a fairly regular basis.  If I just make it a habit than I will stick with it.

DJ


Read More News  RSS Feed 
 

Home | News | Calendar | School Board | Login
Powered by WebSite Manager a GCM Application
Server Time: 9/9/2010 2:22:50 AM | Load Time: 31.2502 ms