Difference between revisions of "DD Class3"

esse quam videri
Jump to: navigation, search
(DataControls)
(Review HW)
Line 5: Line 5:
 
Questions?
 
Questions?
  
Show bind to XML for State and Country
+
VNP how to connect ia VPN. You have all access to our network off campus. VPN will allow you to use local machine names iamdbv.iam.local or siam2.iam.local from off campus.
 +
 
 +
http://imamp.colum.edu/mediawiki/index.php/IAM_VPN
  
 
==Validators==
 
==Validators==

Revision as of 19:21, 26 September 2011


Review HW

Questions?

VNP how to connect ia VPN. You have all access to our network off campus. VPN will allow you to use local machine names iamdbv.iam.local or siam2.iam.local from off campus.

http://imamp.colum.edu/mediawiki/index.php/IAM_VPN

Validators

Validating Input

Using aspx validators

Types of validations and error messages

http://msdn2.microsoft.com/en-us/library/aa479045.aspx

Require Field Validator

<csharp> <asp:RequiredFieldValidator id="valid1_validator"

       ControlToValidate="valid1"
       Display="Static"
       runat="server">
         * Must not be empty 

</asp:RequiredFieldValidator> </csharp>

http://iam.colum.edu/dd/classsource/class4/validation/validator_require.aspx http://iam.colum.edu/dd/gbrowser.php?file=/classsource/class4/validation/validator_require.aspx

Range validator

This example shows the validate method and how to show or not show the error message manually

http://iam.colum.edu/dd/classsource/class4/validation/validator_range.aspx http://iam.colum.edu/dd/gbrowser.php?file=/classsource/class4/validation/validator_range.aspx

<csharp> <asp:rangevalidator runat="Server" id="age_range" controltovalidate="age" display="dynamic" errormessage="Age must be an integer between 18 and 65." minimumvalue="18" maximumvalue="65" Type="Integer" EnableClientScript="False">

     *

</asp:rangevalidator> </csharp>

manually check the Page.IsValid state <csharp>void Page_Load() {

   //This example shows the validate method and how to show or not show the error message manually
   if(Page.IsPostBack){
       //You can manully call Validate() whenevr you like 
       Page.Validate();
       
       //Now we need to check id the results
       if(!Page.IsValid)
       {
           //Check each control and update the error message apropriately
           if(!age_required.IsValid){
               errorMessage.Text = age_required.ErrorMessage + "
"; } else if(!age_range.IsValid){ errorMessage.Text = age_range.ErrorMessage + "
"; } } else

{ errorMessage.Text = "no errors"; }

   }  

} </csharp>


Progamatically add and Bind Data

You can dynamically add list items to and control that inherits ListControl ListControl

To add items to a ListControl use the ListControls Items.Add() function

This example assumes the there is a DropDownList called ddlStates <csharp> <asp:DropDownList id="ddlStates" runat="server" > </asp:DropDownList> </csharp> <csharp> //beware code fragment below ListItem li = new ListItem("SomeState", "SS"); //create a listitem ddlStates.Items.Add(li); //add the listitem to the dropdown li = new ListItem("AnotherState", "AS"); //make another listitem ddlStates.Items.Add(li); //add the second listitem </csharp>

http://iam.colum.edu/dd/classsource/class3/DataBindDropDownStates.aspx source

Same this but with RadioButtonList

Data Binding

In class
How to add an array to a table or drop down?
http://iam.colum.edu/datadesign/classsource/binding/CheeseArray.aspx source
CheeseArray.aspx.cs

http://support.microsoft.com/kb/307860

Controls that inherit from ListControls or DataListControl can be databound

DataControls

There are essentially two types of controls that support databinding ListControls and DataBoundControls Presentation Rendering types for data controls

  • ListControl

Repeat a fixed template DropDownList,CheckBoxList,RadioButtonList,BulledList

  • DataBoundControl Iterative Control

More flexable user defined templates

  • DataGrid - very rich table bound controls
  • DataList - column or HTML flow bound control
  • Repeater - lookless data control (no predetermined formating)
  • GridView - very rich table bound controls with Paging Sorting Selecting Editing v 2.0+
  • DetailsView - single record editor Paging Sorting Selecting Editing v 2.0+
  • FormView - single view for form 2.0+

Demo http://iam.colum.edu/datadesign/classsource/binding/WebControls.aspx source http://iam.colum.edu/datadesign/gbrowser.php?file=/classsource/binding/WebControls.aspx.cs

/WebControls.aspx.cs

Data Controls and Templates

There are essentially two types of controls that support databinding ListControls and DataBoundControls

Presentation Rendering types for data controls

ListControl

we looked at list contorls in class 2

Repeat a fixed template

  • DropDownList
  • CheckBoxList
  • RadioButtonList
  • BulledList

DataBoundControl Iterative Control

More flexable user defined templates


  • DataGrid
very rich table bound controls
  • DataList
column or HTML flow bound control
  • Repeater
lookless data control (no predetermined formating)
  • GridView
very rich table bound controls with Paging Sorting Selecting Editing v 2.0+
  • DetailsView
single record editor Paging Sorting Selecting Editing v 2.0+
single view for form 2.0+
Lookless controls that implements all new 2.0+ templates

http://iam.colum.edu/dd/classsource/ado/SimpleADOAllControls.aspx - source

Homework

Make your class and make a collection of you own objects. Then use databinding to diplay the list of object with at least 3 data controls.

Validate your form... we'll do this next time.

Chapter 4 BDD