Archive for geissingert

Disable CheckboxList ListItems for Visual Studio 2003

I needed to disable listitems in a checkboxlist in Visual Studio 2003. Visual Studio 2005 includes a disabled property but Visual Studio 2003 does not. I even tried using reflection to access the hidden setattribute method but that still didn’t have the attribute render to the page.

The following is what I used to accomplish disabled items that are not selected.

  // For Visual Studio 2003. Visual Studio 2005 has a disabled property
  private void SetDisabledCheckBoxItems(CheckBoxList cbl) {
    ArrayList al = new ArrayList();
    for (int i = 0; i < cbl.Items.Count; i++) {
      if (cblProducts.Items[i].Selected == false) {
        al.Add(i.ToString());
      }
    }
    string[] items = al.ToArray(typeof(string)) as string[];
    StringBuilder sb = new StringBuilder();
    sb.Append(“<script language=’javascript’>”);
    sb.Append(” document.onreadystatechange = ReadyStateChange;”);
    sb.Append(” function ReadyStateChange() {“);
    sb.AppendFormat(” var listItems = new Array({0});”string.Join(“,”, items));
    sb.Append(” for (var i = 0; i < listItems.length; i++) {“);
    sb.AppendFormat(” document.getElementById(‘{0}_’ + listItems[i]).disabled = ‘disabled’;”, cbl.ClientID);
    sb.Append(” }”);
    sb.Append(” }”);
    sb.Append(“</script>”);
    Page.RegisterStartupScript(“script”, sb.ToString());
  } 

Comparing 2 String Arrays and returning the matches from them in a generic list collection

I wanted to be able to compare 2 string arrays and find out which ones match. By using 2 generic lists and the FindAll method with anonymous method I was able to have it returned as a new generic list. Code is as follows:

    string[] a1 = { "One", "Two", "Three" };
     string[] a2 = { "Two", "One" };
     List l1 = new List(a1);
     List l2 = new List(a2);
     List li = l1.FindAll(delegate(string s) { return l2.Contains(s); });

Listing of all files including files in a sub directory

    string[] files = System.IO.Directory.GetFiles(path, searchPattern,
SearchOption.AllDirectories);

Bind data using a static method

To bind data using a static method use the following syntax:

<asp:Label ID="Label1" runat="server" 
    Text='<%# Namespace.Class.Method(
                DataBinder.Eval(
                  Container.DataItem, "FieldName")) %>'>
</asp:Label>

Using NT Groups for ASP.Net Webform Access

I had a request come that asked to use NT Groups for access to pages.
After doing some searching I was able to get it to work using the following:

<authentication mode="Windows" />
<identity impersonate = "true" />

<roleManager enabled="true"
     defaultProvider="AspNetWindowsTokenRoleProvider" />

<authorization>
  <allow roles="{domainname}\{NTGroup}" />
  <deny users="*" />
</authorization>

The key item is the roleManager. By adding the tag it knows to use windows groups.
Also I changed the domainname and NTGroup to the group that was used for access.

First day of Devscovery

Today was my first day at Devscovery.

Durning the keynote there was a lot of coverage about Windows Presentation Foundation (WPF) and how it is going to make creating a application that will be able to run in either a web browser or as a windows application. It has a lot of functionally in it that is going to make resizing a application to the screen resolution something that will be handled without having to deal with it thru code. It will also allow the user to change the font size and it will handle the changes for the user.

Both the second and fourth sessions that I attended had to dealt with security for a web site. It gave great insight into how to code to handle many of the issues.

The third session was on exception handling. It gave great insight into the perspectives that the designers used when laying the foundation for exception handling. It was very informative. But Greg, I still don’t agree with all of it… Sorry.

There was a lot of great information. Ink and handwritting applications look to be an area where things are going to grow as time goes by. I’m looking forward to the next 2 days.

Format code to html with Visual Studio and Microsoft Word

1. Load a blank HTML Page.

2. Start Microsoft Word.

3. Copy the code from visual studio.

4. Paste the code into Word.

5. Copy the code from Word.

6. Paste the code into the blank HTML Page.

7. When the code is pasted it is pasted with the needed HTML.

Transforming Xml with Xsl in Memory

I have wanted to be able to transform Xml data that is in memory with Xsl.

This method will allow the transformation of the Xml using the Xsl and return what has been transformed as a string.

  /// <summary>
  /// In memory XSL transformation.
  /// </summary>
  /// <param name="xmlText">The XML text.</param>
  /// <param name="xslText">The XSL text.</param>
  /// <returns>Xsl transformation of data of the Xml.</returns>
  private string InMemoryXslTransformation(string xmlText, string xslText) {

    // load instance of xml to a XmlDocument from xmlText
    XmlDocument xml = new XmlDocument();
    xml.InnerXml = xmlText;

    // load instance of xsl to a XmlDocument from xslText
    XmlDocument xsl = new XmlDocument();
    xsl.InnerXml = xslText;

    // xsl argument list for xsl compiled transformation
    XsltArgumentList al = new XsltArgumentList();

    // hold output from xsl compiled transformation
    StringWriter sw = new StringWriter();

    // create instance of XslCompiledTransform object
    XslCompiledTransform xslTrans = new XslCompiledTransform();

    // load the XSLT style sheet
    xslTrans.Load(xsl);

    // transfor the XML file using the XSLT file
    // store the output in a StringWriter object
    xslTrans.Transform(xml, al, sw);

    // output message
    return sw.ToString();
  }

Windows Live Writer blogging software

I downloaded a new program to create blogs and needed a blog to test it so that is the reason that I created this blog. I downloaded Windows Live Writer.