Great Resource For Visual Studio Color Schemes/Themes

http://studiostyl.es/

Advertisements

How To Copy Schema And Data From One SQL Server Instance To Another

Within Microsoft SQL Server Management Studio 2008:

  1. Right click the database
  2. Select Tasks -> Generate Scripts
  3. (Click next if you get the intro screen)
  4. Select “Select specific database objects”
  5. Pick the objects to generate scripts for (tables, stored procedures, etc…)
  6. Click Next, then specify the output filename
  7. Click Finish to generate the script

This will generate the schemas only. If you want to do data generating scripts as well, in step 6) click the Advanced button and scroll down to the “Types of data to script” and change it from “Schema only” to “Data only” or “Schema and data”

How To Use PagedDataSource To Paginate Repeater (Prev/Next/First/Last and Page Numbers)

I needed to add pagination to my Repeater control. The requirements where that a First/Last Next/Prev buttons be available as well as a list of the available pages so users could visit any page they wanted. (1 | 2 | 3..).

Below is the result using a few articles as reference for the implementation:

<%@ Page Language="C#" MasterPageFile="~/admin/paperless/Paperless.master" Inherits="Company.Common.Objects.CompanyPage"
    Title="Paperless Interest" %>

<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="Admin.Redesign.Layers" %>
<%@ Import Namespace="Admin.Redesign.Objects" %>
<%@ Import Namespace="Company.Common.Layers" %>
<%@ Import Namespace="Company.Common.Objects" %>
<%@ Import Namespace="Company.Common.Objects.DataObjects" %>

<script runat="server">       
    
    protected List<PaperlessActivity> _Reminders = new List<PaperlessActivity>();

    protected int CurrentPage
    {
        get
        {
            // look for current page in ViewState
            object o = this.ViewState["_CurrentPage"];
            if (o == null)
                return 0;	// default to showing the first page
            else
                return (int)o;
        }

        set
        {
            this.ViewState["_CurrentPage"] = value;
        }
    }

    protected int PageCount
    {
        get
        {
            // look for current page count in ViewState
            object o = this.ViewState["_PageCount"];
            if (o == null)
                return 1;	// default to just 1 page
            else
                return (int)o;
        }

        set
        {
            this.ViewState["_PageCount"] = value;
        }
    }


    protected void GetItems()
    {
        PagedDataSource pagedData = new PagedDataSource();

        pagedData.AllowPaging = true;
        pagedData.PageSize = 10;
        pagedData.DataSource = PaperlessLogic.GetInterestList();
        pagedData.CurrentPageIndex = CurrentPage;


        lblCurrentPage.Text = "<b>Page:</b> " + (CurrentPage + 1).ToString() + " of " + pagedData.PageCount.ToString();

        PageCount = pagedData.PageCount;

        // Disable Prev/Next First/Last buttons if necessary
        cmdPrev.Enabled = !pagedData.IsFirstPage;
        cmdFirst.Enabled = !pagedData.IsFirstPage;
        cmdNext.Enabled = !pagedData.IsLastPage;
        cmdLast.Enabled = !pagedData.IsLastPage;



        // Wire up the page numbers
        if (pagedData.PageCount > 1)
        {
            rptPages.Visible = true;
            ArrayList pages = new ArrayList();
            for (int i = 0; i < pagedData.PageCount; i++)
                if (i == CurrentPage)
                {

                    pages.Add("<b>" + (i + 1).ToString() + "</b>");
                }
                else
                {
                    pages.Add((i + 1).ToString());
                }
            rptPages.DataSource = pages;
            rptPages.DataBind();
        }
        else
        {
            rptPages.Visible = false;
        }



        RptPaperless.DataSource = pagedData;
        RptPaperless.DataBind();
    }

    protected void cmdPrev_Click(object sender, System.EventArgs e)
    {
        // Set viewstate variable to the previous page
        CurrentPage -= 1;

        // Reload control
        GetItems();
    }

    protected void cmdNext_Click(object sender, System.EventArgs e)
    {
        // Set viewstate variable to the next page
        CurrentPage += 1;

        // Reload control
        GetItems();
    }

    protected void cmdFirst_Click(object sender, System.EventArgs e)
    {
        // Set viewstate variable to the first page
        CurrentPage = 0;

        // Reload control
        GetItems();
    }
    protected void cmdLast_Click(object sender, System.EventArgs e)
    {
        // Set viewstate variable to the last page
        CurrentPage = PageCount - 1;

        // Reload control
        GetItems();
    }

    protected void rptPages_ItemCommand(object source,
                             RepeaterCommandEventArgs e)
    {
        CurrentPage = Convert.ToInt32(e.CommandArgument) - 1;
        GetItems();
    }

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        rptPages.ItemCommand +=
           new RepeaterCommandEventHandler(rptPages_ItemCommand);
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        GetItems();
    }

    protected bool CurrentPageHighlight(int currPage)
    {
        return currPage == CurrentPage ? true : false;
    }
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="cphContent" runat="Server">
    <asp:ScriptManager ID="ScriptManager" runat="server" />
    <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
        <ContentTemplate>
            <h1>
                Paperless Interest</h1>
            <asp:Repeater ID="RptPaperless" runat="server">
                <HeaderTemplate>
                    <table class="tableData" cellpadding="0" cellspacing="0">
                        <tr>
                            <th>
                                Interest ID
                            </th>
                            <th>
                                Interest Date
                            </th>
                            <th>
                                Utility
                            </th>
                            <th>
                                OpCo
                            </th>
                            <th>
                                State
                            </th>
                            <th>
                                Channel
                            </th>
                            <th>
                                Created By
                            </th>                           
                            <th>
                                Account #
                            </th>
                            <th>
                                Customer Email
                            </th>
                            <th>
                                Customer Name
                            </th>
                        </tr>
                </HeaderTemplate>
                <FooterTemplate>
                    </table>
                </FooterTemplate>
                <ItemTemplate>
                    <tr>
                        <td>
                            <a href="Edit.aspx?id=<%# Eval("InterestID") %>">Edit</a>:
                            <%# Eval("InterestID") %>
                        </td>
                        <td>
                            <%# Eval("CreatedDate", "{0:M/d/yyyy h:mm:ss tt}") %>
                        </td>
                        <td>
                            <%# Eval("UtilityName") %>
                        </td>
                        <td>
                            <%# Eval("OpCoNumber") %>
                        </td>
                        <td>
                            <%# Eval("StateCode") %>
                        </td>
                        <td>
                            <%# Eval("Channel.ChannelName") %>
                        </td>
                        <td>
                            <%# Eval("CreatedBy") %>
                        </td>                        
                        <td>
                            <%# Eval("CustomerAccountNumber") %>
                        </td>
                        <td>
                            <%# Eval("CustomerEmail") %>
                        </td>
                        <td>
                            <%# Eval("CustomerName") %>
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>
            <br />
            <center>
                <div>
                    <div>
                        <asp:Label ID="lblCurrentPage" runat="server"></asp:Label></div>
                    <div>
                        <table>
                            <tr>
                                <td>
                                    <asp:Button ID="cmdFirst" runat="server" Text="<< First" OnClick="cmdFirst_Click">
                                    </asp:Button>&nbsp;
                                </td>
                                <td>
                                    <asp:Button ID="cmdPrev" runat="server" Text="< Prev" OnClick="cmdPrev_Click"></asp:Button>&nbsp;
                                </td>
                                <td>
                                    <asp:Repeater ID="rptPages" runat="server">
                                        <HeaderTemplate>
                                            <table cellpadding="0" cellspacing="0" border="0">
                                                <tr class="text">
                                                    <td>
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:LinkButton ID="btnPage" CommandName="Page" CommandArgument="<%# Container.DataItem %>"
                                                runat="server"><%# Container.DataItem %>
                                            </asp:LinkButton>&nbsp;
                                        </ItemTemplate>
                                        <FooterTemplate>
                                            </td> </tr> </table>
                                        </FooterTemplate>
                                    </asp:Repeater>
                                </td>
                                <td>
                                    &nbsp;<asp:Button ID="cmdNext" runat="server" Text="Next >" OnClick="cmdNext_Click">
                                    </asp:Button>
                                </td>
                                <td>
                                    &nbsp;<asp:Button ID="cmdLast" runat="server" Text="Last >>" OnClick="cmdLast_Click">
                                    </asp:Button>
                                </td>
                            </tr>
                        </table>
                    </div>
                    &nbsp;</div>
            </center>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>

References: