Navigation

Search

Categories

On this page

Common Solutions for T-SQL Problems
Searching in WSS 3.0 and MOSS 2007
How to move a WSS 3.0 Database to another server
Free Web Site Templates
Editing in a ListView
Login User Control
Exposing Events from a User Control
Check/Uncheck All Checkboxes in a GridView
User Controls
A Styled GridView
Make your own AJAX "loading" icons

Archive

Blogroll

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

RSS 2.0 | Atom 1.0 | CDF

Send mail to the author(s) E-mail

Total Posts: 125
This Year: 63
This Month: 0
This Week: 0
Comments: 0

Sign In

 Thursday, June 26, 2008
Thursday, June 26, 2008 11:05:44 AM (Eastern Standard Time, UTC-05:00) ( )


This site from Microsoft has some great T-SQL examples: http://code.msdn.microsoft.com/SQLExamples

 Friday, June 20, 2008
Friday, June 20, 2008 10:49:11 AM (Eastern Standard Time, UTC-05:00) ( )

 

I've been having trouble getting WSS to index certain documents and working correctly and this article was helpful.

http://www.wrox.com/WileyCDA/Section/id-305250.html

Friday, June 20, 2008 9:18:50 AM (Eastern Standard Time, UTC-05:00) ( )

 

How do I move WSS 3.0 for "Windows Internal Database" (the embedded version of SQL Server 2005 Express) to the full SQL Server 2005?

Description:

This text was written by Jim Sykora in a public newsgroup and he has very kindly allowed me to re-produce it here.
Many thanks, Jim.
-------
This scenario involves moving your WSS 3.0 sites from Windows Internal Database to Microsoft SQL 2005 (doesn't really matter whether it's local or remote to the main WSS server instance).

1. First Fully backup your current WSS Content databases. I've found no way to move config databases, and from my testing there seems to be little reason to do so.
a. Utilize stsadm.exe from a cmd prompt to back up your entire Sharepoint farm:
stsadm.exe -o backup -url http:// -filename C:\SPBackups\FullFarmBackup.dat
(you may want to change the path the backup file is stored depending on your situation)

b. Verify the backup is complete and browse to the location the backup file is stored to verify it exists and is of a reasonable size.

2. Uninstall WSS 3.0 from Add/Remote Programs Control Panel

3. *IMPORTANT* Remove Windows Internal Database -
http://support.microsoft.com/kb/920277
If you were utilizing a single-server, basic WSS 3.0 installation and uninstall it, it will leave behind the Windows Internal Database, which will cause any new installations of WSS 3.0 to have issues.

4. Reboot the server to finish up any uninstall scripts.

5. Make sure your SQL 2005 database is prepped per the instructions for installing a WSS 3.0 Server Farm and then install using the steps for a server farm (even if you'll only be installing on a single server).
a.
http://technet2.microsoft.com/WindowsServer/WSS/en/library/89e4c579-5720-45e
0-917e-abeb95266c3e1033.mspx

b.
http://technet2.microsoft.com/windowsserver/WSS/en/library/1f505e96-60e2-41a
c-bf5d-9739105f047c1033.mspx?mfr=true

6. Once everything is installed and you're using the SharePoint Products and Technologies Configuration Wizard to configure sharepoint make sure to point it to your existing SQL server as you go through the steps.

7. Upon completion of the wizard use WSS 3.0 Central Administration page to configure your basic settings such as Incoming and outgoing email settings, logging, search server, etc.

8. In Central Administration->Application Management choose "Create or Extend Web Application" to create your IIS instance. Follow the standard steps here.

9. In Central Administration->Content Databases choose "Add a content database" and use your SQL server. Don't forget to select your search server that you set up earlier. This will create an empty content
database which we will restore our site from step 1 to.

10. Open a command prompt again. Use stsadm.exe to restore your site farm:
ststadm.exe -o restore -url http:// -filename C:\SPBackups\FullFarmBackup.dat
This step will take a little bit, but should say Operation Completed Successfully at the end. You should now be able to access your sharepoint site again using the new SQL server database location.

This should also work as a disaster recovery process starting at step 2 being that you should have daily or weekly scheduled sharepoint backups using stsadm (and at least monthly SQL database backups to help with SQL performance and log management).

Later: Boris Gomiunik has a blog item on the way he did this here -

http://webborg.blogspot.com/2007/06/reinstalling-sharepoint-wss3-to-run.html

 Thursday, May 29, 2008
Thursday, May 29, 2008 9:25:44 PM (Eastern Standard Time, UTC-05:00) ( )

My design skills are terrible so I often look for templates or "borrow" other people's design ideas. One of the better sites I've found for templates is http://www.opendesigns.org/

 Friday, May 23, 2008
Friday, May 23, 2008 2:30:20 PM (Eastern Standard Time, UTC-05:00) (  |  )


This is based on Matt Beserth's article, Modifying Data with the ListView's EditItemTemplate

Here is my own example.

 Thursday, May 22, 2008
Thursday, May 22, 2008 10:29:08 AM (Eastern Standard Time, UTC-05:00) (  |  )

This is a simple login user control used to demonstrate how to expose (get and set) the properties associated with the control. Here is a working demo.

** LoginUserControl.ascx **

<script language="VB" runat="server">

  Public BackColor As String = "white"

  Public Property Login As String
    Get
      Return txtLogin.Text
    End Get
    Set
      txtLogin.Text = Value
    End Set
  End Property

  Public Property Password As String
    Get
      Return txtPassword.Text
    End Get
    Set
      txtPassword.Text = Value
    End Set
  End Property
  
  Public Property Status As String
  Get
      Return lblStatus.Text
  End Get
  Set
      lblStatus.Text = Value
  End Set
  End Property

</script>

<table style="background-color:<%=BackColor%>;font: 10pt verdana;border-width:1;border-style:solid;border-color:black;" cellspacing=15>
  <tr>
    <td><b>Login: </b></td>
    <td><ASP:TextBox id="txtLogin" runat="server"/></td>
  </tr>
  <tr>
    <td><b>Password: </b></td>
    <td><ASP:TextBox id="txtPassword" TextMode="Password" runat="server"/></td>
  </tr>
  <tr>
    <td></td>
    <td><ASP:Button Text="Submit" runat="server"/></td>
  </tr>
  <tr>
    <td></td>
    <td><asp:Label id="lblStatus" runat="server"/></td>
  </tr>  
</table>

** LoginControl.aspx **

<%@ Register TagPrefix="MyUserControl" TagName="Login" Src="LoginUserControl.ascx" %>

<html>

<script language="VB" runat="server">
    Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
        If (Page.IsPostBack) Then
            MyLabel.Text &= "The UserId is " & MyLogin.Login & "<br>"
            MyLabel.Text &= "The Password is " & MyLogin.Password & "<br>"
            MyLogin.Status = "Hello world"
        End If
    End Sub
</script>

<body style="font: 10pt verdana">
  <h3>A Login User Control</h3>

  <form runat="server">
    <MyUserControl:Login id="MyLogin" UserId="John Doe" Password="Secret" BackColor="beige" runat="server"/>
  </form>
  <asp:Label id="MyLabel" runat="server"/>
</body>
</html>
Thursday, May 22, 2008 9:41:16 AM (Eastern Standard Time, UTC-05:00) ( )

You can expose events from a user control.  After you expose the event, you can handle the event in the page that contains the user control. Exposing events is useful when you need to pass information up to the containing page.  In this example, we create a custom tab strip with a user control. When a user clicks a tab, the content is changed. 

The TabStrip control exposes an event named TabClick. This event is raised in the dlstTabStrip_SelectedIndexChanged() event handler when a tab is clicked.

Here is a working demo.

** TabStripUserControl.ascx **

<%@ Control Language="VB" ClassName="TabStrip" %>
<%@ Import Namespace="System.Collections.Generic" %>
<script runat="server">
 
    Public Event TabClick As EventHandler
 
    ''' <summary>
    ''' The index of the selected tab
    ''' </summary>
    Public ReadOnly Property SelectedIndex() As Integer
        Get
            Return dlstTabStrip.SelectedIndex
        End Get
    End Property
 
    ''' <summary>
    ''' Create the tabs
    ''' </summary>
    Private Sub Page_Load()
        If Not Page.IsPostBack Then
            ' Create the tabs
            Dim tabs As New List(Of String)()
            tabs.Add("Products")
            tabs.Add("Services")
            tabs.Add("About")
 
            ' Bind tabs to the DataList
            dlstTabStrip.DataSource = tabs
            dlstTabStrip.DataBind()
 
            ' Select first tab
            dlstTabStrip.SelectedIndex = 0
        End If
    End Sub
 
    ''' <summary>
    ''' This method executes when a user clicks a tab
    ''' </summary>
    Protected Sub dlstTabStrip_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
        RaiseEvent TabClick(Me, EventArgs.Empty)
    End Sub

</script>

<asp:DataList   
    id="dlstTabStrip"
    RepeatDirection="Horizontal"
    OnSelectedIndexChanged="dlstTabStrip_SelectedIndexChanged"
    CssClass="tabs"
    ItemStyle-CssClass="tab"
    SelectedItemStyle-CssClass="selectedTab"
    Runat="server">
    <ItemTemplate>
    <asp:LinkButton
        id="lnkTab"
        Text='<%# Container.DataItem %>'
        CommandName="Select"
        Runat="server" />
    </ItemTemplate>
</asp:DataList> 
 

** TabStrip.aspx **

   
<%@ Page Language="VB" %>
<%@ Register TagPrefix="user" TagName="TabStrip" Src="TabStripUserControl.ascx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">
 
    Protected Sub TabStrip1_TabClick(ByVal sender As Object, ByVal e As EventArgs)
        MultiView1.ActiveViewIndex = TabStrip1.SelectedIndex
    End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <style type="text/css">
        html
        {
            background-color:silver;
            font:14px Georgia,Serif;
        }
        .tabs a
        {
            color:blue;
            text-decoration:none;
            font:14px Arial,Sans-Serif;            
        }
        .tab
        {
            background-color:#eeeeee;
            padding:5px;
            border:Solid 1px black;
            border-bottom:none;
        }
        .selectedTab
        {
            background-color:white;
            padding:5px;
            border:Solid 1px black;
            border-bottom:none;
        }
        .views
        {
            background-color:white;
            width:400px;
            border:Solid 1px black;
            padding:10px;
        }
    </style>
    <title>Show TabStrip</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    <user:TabStrip
        ID="TabStrip1"
        OnTabClick="TabStrip1_TabClick" 
        Runat="Server" />
        
    <div class="views">
    <asp:MultiView
        id="MultiView1"
        ActiveViewIndex="0"
        Runat="server">
        <asp:View ID="Products" runat="server">
            <h1>Products</h1>
            We sell a variety of useful products...
        </asp:View>
        <asp:View ID="Services" runat="server">
            <h1>Services</h1>
            We offer a number of services...
        </asp:View>
        <asp:View ID="About" runat="server">
            <h1>About</h1>
            We were the first company to offer products and services...
        </asp:View>
    </asp:MultiView>
    </div>
        
    </div>
    </form>
</body>
</html>
 Wednesday, May 14, 2008
Wednesday, May 14, 2008 8:22:37 AM (Eastern Standard Time, UTC-05:00) (  |  )

Having the ability to check or uncheck all of the checkboxes which appear inside of a GridView is a frequent requirement.  There are several javascript libraries which will handle this on the client-side which is usually the better way to go, but this can also be done server-side and along with an AJAX UpdatePanel can be pretty elegant.  Here is a working demo.

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
       
    Protected Sub MasterCheck_Click(ByVal sender As Object, ByVal e As CommandEventArgs)
        'Enumerate each GridViewRow
        For Each gvr As GridViewRow In GridView1.Rows
            'Programmatically access the CheckBox from the TemplateField
            Dim cb As CheckBox = CType(gvr.FindControl("Checkbox1"), CheckBox)
            
            Select Case e.CommandName

                Case "Check"
                    'Check all of the checkboxes
                    cb.Checked = True
                    'Change the CommandName, CommandArgument and Text of the button
                    btnMasterCheck.CommandName = "Uncheck"
                    btnMasterCheck.CommandArgument = "Uncheck"
                    btnMasterCheck.Text = "Uncheck All"
                Case "Uncheck"
                    'Uncheck all of the checkboxes
                    cb.Checked = False
                    'Change the CommandName, CommandArgument and Text of the button
                    btnMasterCheck.CommandName = "Check"
                    btnMasterCheck.CommandArgument = "Check"
                    btnMasterCheck.Text = "Check All"
                Case Else

            End Select
        Next
    End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Check/Uncheck All Checkboxes in a GridView</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:SqlDataSource
        id="srcMovies"
        ConnectionString='<%$ ConnectionStrings:MyDatabase %>'
        SelectCommand="SELECT Title, Director FROM Movies ORDER BY Title"
        Runat="server" />
        
        <asp:ScriptManager id="sm1" runat="server" />

    <asp:UpdatePanel id="UpdatePanel1" Runat="server">
   
    <ContentTemplate>
        <asp:GridView ID="GridView1" runat="server" DataSourceID="srcMovies" AutoGenerateColumns="False">
        <Columns>
         <asp:TemplateField HeaderText="">
                 <ItemTemplate>
                    <asp:Checkbox id="Checkbox1" runat="server"  /> 
                 </ItemTemplate>
          </asp:TemplateField> 
         
         <asp:BoundField HeaderText="Title" DataField="Title" />
         <asp:BoundField HeaderText="Director" DataField="Director" />
        </Columns>
        </asp:GridView><br />
        <asp:Button ID="btnMasterCheck" runat="server" CommandName="Check" CommandArgument="Check" OnCommand="MasterCheck_Click" Text="Check All" />
    </ContentTemplate>
    </asp:UpdatePanel>
    
    </div>
    </form>
</body>
</html>
 Monday, May 12, 2008
Monday, May 12, 2008 2:01:26 PM (Eastern Standard Time, UTC-05:00) ( )


User controls are somewhat outdated already with the introduction of partial classes in ASP.NET 2.0 but I still find them useful.  I think of them similar to the include pages in classic ASP. This is a simple example of how to get the text value from a user control on the parent page.

<%@ Page Language="VB" %>
<%@ Register Src="header.ascx" TagName="header" TagPrefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Sub Page_Load(ByVal Src As Object, ByVal E As EventArgs)
    Dim CompanyName As TextBox = CType(Page.FindControl("Header1$txtCompanyName"), TextBox)
    lblCompanyName.Text = CompanyName.Text   
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    <!--This is my user control page header-->
     <uc1:header id="Header1" runat="server"></uc1:header>
     <br />
     <br />
     <asp:Label ID="lblCompanyName" runat="server" Text="Label" />     
     <asp:TextBox ID="TextBox1" runat="server" />    
    </div>
    </form>
</body>
</html>

This is an example of how to set the text value from inside the user control on the parent page.

<%@ Control Language="VB" ClassName="header" EnableViewState="false" %>

<script runat="server">
        
    Private Sub Page_Load(ByVal Src As Object, ByVal E As EventArgs)
        If Not Page.IsPostBack Then                        
            Dim TextBox1 As Textbox =CType(Me.Parent.FindControl("TextBox1"),TextBox)
            TextBox1.Text = "Eat your veggies"            
        End If
    End Sub
</script> <table width="100%" border="0" cellpadding="3" cellspacing="0"> <tr> <td>Company: <asp:Textbox ID="txtCompanyName" runat="server" CssClass="textbox" Text="Company Name" ToolTip="Enter a company name" />
<asp:Button ID="btnCompanySearch" runat="server" Text="go" CssClass="buttons" OnClick="QuickSearch_Companies_Click" /></td> </tr> </table>
 Wednesday, May 07, 2008
Wednesday, May 07, 2008 12:43:11 PM (Eastern Standard Time, UTC-05:00) ( )


I've been following Matt Berseth's .NET Developer's Blog and he has some great stuff on here. The example below is from his post on Building a VS2008 Styled Grid with the GridView Control.  I've made simpler variation of his here.

First the style sheet where all of the real magic happens:

body 
{
    background-color: Aliceblue;
    font-family:Tahoma;
    font-size: 12px;
}

.grid 
{ 
    width:90%; 
    font-family:Tahoma; 
    display: block;
    margin-left: auto;
    margin-right: auto      
}

.director
{
    color: Green;
}

.grid .datatable
{
    width:100%;
    color:#666;
}        
.grid .datatable TH
{
    font-size:12px;
    font-weight:bold;
    letter-spacing:0px;
    text-align:left;
    padding:2px 4px;
    color:#333333;
    border-bottom:solid 2px #bbd9ee;
}
.grid .datatable TH A
{ 
    text-decoration:none;
    padding-right:18px; 
    color:#0066cc;
}

.grid .datatable .row TD
{
    font-size:11px;
    text-align:left;
    padding:6px 4px;
    border-bottom:solid 1px #bbd9ee;
}      
.grid .datatable .row:hover
{
    background-color:#fffacd;
    color:#000;
}
.grid .datatable .row TD.first { padding-left:10px; }
.grid .datatable TH.first { padding-left:10px; }
.grid .datatable .row:hover .first
{
    background-repeat:no-repeat;   
    background-image:url(../img/bullet.gif);
}  

Then the .aspx page itself

<form id="form1" runat="server">
    <div>
    <asp:SqlDataSource
        id="srcMovies"
        ConnectionString='<%$ ConnectionStrings:MyDatabase %>'
        SelectCommand="SELECT Title, Director FROM Movies ORDER BY Title"
        Runat="server" />       
             
       <div class="grid"> 
        <asp:GridView ID="GridView1" runat="server" BorderStyle="None" DataSourceID="srcMovies" HorizontalAlign="Center" 
        CssClass="datatable" AutoGenerateColumns="false" BorderWidth="1px" BackColor="White" GridLines="Horizontal">
       <RowStyle CssClass="row" />
       <Columns>
             <asp:BoundField DataField="Title" HeaderText="Title" ItemStyle-CssClass="first" />
             <asp:BoundField DataField="Director" HeaderText="Director" ItemStyle-CssClass="director" />       
       </Columns>         
        </asp:GridView>        
       </div>        
    </div>
    </form>
Wednesday, May 07, 2008 12:41:45 PM (Eastern Standard Time, UTC-05:00) ( )