Friday, September 21, 2007

Huntington Beach, California, Data Repeater List Developers

ASP.NET developers, Huntington Beach, California
Understanding The Data Repeater and Data List controls for
A. Understanding the HTML templates under the surface.
B. Bottom line…Data appears in a template
C. A template is just the html between the template tags
D. There are many “types of templates”
E. Some for headers/footers, Some for data
2. Displaying Data
A. DataRepeater repeats a template you design for each row.
B. So your are not restricted to tabular data
1. But no in line edit like the Grid
2. And no template “editor” like Grid
a) You just “roll your own” in HTML view…easy.
3. Hooking it up
A. Assign a DataSource
B. Adds templates to the Items collection
1. ItemTemplate row = all items…repeats for each row.
2. AlternatingItemTemplate …for odd number rows
C. The flow
1. HeaderTemplate
2. ItemTemplate (first data row)
3. SeparatorTemplate (between rows)
4. AlternatingItemTemplate (second data row)
5. repeat….
6. FooterTemplate
4. To output data
B. DataBinder Class allows for data binding
1. .Eval triggers the binding
2. Container is the template…DataItem is the current row in the template
3. “FieldName” is the datafield of the current row
5. Configuring:
A. Place the Repeater on the HTML view
B. This creates a bulleted list of CatgoryNames
7. AlternatingItemTempate
A. Copy the ItemTempate once it is perfect
B. Paste below and change the tags to Alternating…and change formatting
8. SeparatorTemplate

B. creates a left aligned horizontal line.
9. ItemCommand…just like datagrid or datalist
A. Triggered click on link or button in the control
B. Returns e.
1. CommandArgument: attribute you can set with a value
2. CommandName: you can set with a value
3. CommandSource: what you clicked on
4. Item: The Item (row) you clicked on.

Saturday, September 8, 2007

ASP.NET Hyperlink Grid California Irvine Developers

ASP.NET California Irvine Developers

1. Hyperlink Column: Grid . PropertyBuilder . Hyperlink
A. Text Field: The field.value to display in the column
1. (hint Text = Static text in column…all same)
B. URL Field: The field.value to pass in the hyperlink.
C. URL Format = PageName.aspx?Var={0} where 0 is the URL Field above
1. Var will hold the value in {0}…
2. How they hook together to jump to a detail a detail page
A. When you click on the hyperlink displayed in the Text Field
B. The Value from URL Field is inserted into the {0} location in the URL Format.
C. So when you click on a hyperlink you are sent to the page indicated along with the value you indicate
D. The Edit page opens and a select statement returning just one row from the ID passed by Request.QueryString(“ID”)
E. This allows you to pass the ID to a detail page for Editing.
3. Displaying the values on a detail page. (extra credit on homework)
A. Textboxes = easy! txtProductName.Text = dr(“ProductName”).ToString
B. Select List is tricky
C. Goal is to Set the SelectedIndex property to the field value
1. Old days…loop and check each item in the list until there was a match
2. Now use FindByValue to get the matching Item from the DataValue list.
3. ListItem = SelectList.Items.FindByValue(Value)
a) returns the list Item who’s value matches the value you sent it.
4. SelectList.SelectedIndex = SelectList.Items.IndexOf(ListItem)
a) Now you have the proper ListItem…this sets the index of selected index of the SelectList to the index of the ListItem you found.
5. Bottom Line…the SelectList displays your item.
4. Saving an Item from the detail page
A. In real life you have to validate your data before this but…..assuming that is done.
B. Goal is create the proper SQL Update statement.
1. String.Format(“update products set field = {0},field={1},etc
a) Where ID = Request.QueryString(“ID”)”
b) ,fieldOneValue, fieldTwoValue, etc
C. Converting the values for the database
1. Text Values
a) Book has you create a DataHandler.QuoteString(textvalue)
(1) 1) checks for embedded single quotes and replaces with two single quotes (ie O’Neil)
(2) 2) wraps all the text with single quotes.
2. SelectList.SelectedItem.Value are OK in native format
3. Check boxes use CInt(checkbox.Checked)
D. The entire string is passed to the DataHandler that will take care of the details of running the command.ExecuteNonQuery.
5. In place editing on the Grid
A. Concept: Property Builder: Button Column: Edit
1. User clicks on Edit
2. On PostBack, EditCommand captures which row was selected
3. grid.EditItemIndex = that row puts that row in edit mode.
4. The rebind the grid.
B. Default is bound column data is display in a text box (input)
C. EditMode replaces Edit hyperlink with Update Cancel
1. And replaces data with editable boxes.
D. Edit,Update,Cancel Button Column
1. Creates an “Edit” link (or Edit Button) Column
E. Clicking on this Triggers a PostBack and raises the EditCommand event
1. and returns which row has been clicked on. (.ItemIndex)
F. To trigger the edit set the EditItemIndex to the row selected
1. grid.EditItemIndex = e.Item.ItemIndex
G. Then Rebind the datasource to the grid
1. This is a postback…requires rebinding
6. SmartNavigation: IE5 or greater
A. Saves position on the page…and puts you back in same place
1. Note normal HTML behavior
B. Stops navigation flicker
C. In PageLoad Set Page.SmartNavigation=True
1. grid.EditItemIndex = e.Item.ItemIndex works perfect!
7. But what if not IE5 or greater
A. The user is placed at top of page…and your edit row may be down below screen! Bad
B. So we return only the row to be edited…not the entire list
C. Use a DataView and set it’s filter
1. dv.RowFilter = “ProductID=”&e.Item.Cells(2).Text
a) This says use the 3rd column (cells(2)) to filter row…the ID Column
2. and tell grid to edit it’s first (and only) row
a) grid.EditItemIndex=0
8. How do we determine if IE5 or greater?
A. Request.Browser.Browser =” IE”
B. Request.MajorVersion >= 5
C. And for testing only
2. Setting this constant to True in page load makes it act like before IE5
9. Add vs Edit (Update)
A. Session(“AddMode”)=T or F based upon clicking on the Add Link
B. If Add= True then use SQL Insert otherwise use SQL Update
10. Saving Data: Clicking on Update triggers the _UpdateCommand
A. Getting the data from the e.Item (the row being editing)
B. Each column = a cell so the third cell is e.Item.Cells(2)
C. If the data is just text…not any type of control
1. var = e.Item.Cells(2).Text
D. But any type of control requires…controls collection and conversion.
1. var = Ctype(e.Items.Cells(3).Controls(0),TextBox).Text
2. goes the first control in 4th column
3. converts the control into a textbox
4. returns the text property of the text box
E. Once you have all the data then
1. Check to see if AddMode is true
2. and issue the SQL Update or Insert
F. Reset the AddMode Flag
G. Turn off EditMode
1. grid.EditItemMode = -1
H. Rebind the grid.
11. Canceling the Update: Triggers the _CancelUpdate
A. Easy: Turn off Editmode
1. grid.EditItemMode = -1
2. Rebind the grid
12. Template Column
A. You define what control displays data in Item View and Edit View
B. Concept…in Property Builder you tell the grid which columns are template columns
C. In right click properties of the grid you can Edit the template columns
1. Easy….just select the column template to edit
D. Template Editor: ItemTemplate is normal display, EditItemTemplate is used during EditItemMode=True
1. Example…Hyperlink in normal but text box in edit
E. Binding the custom controls…use their databinding properties
1. Select the property to bind…usually text
2. DataBinder.Eval(Container, "DataItem.ProductName")
F. And modify the UpdateCommand
1. In most cases you now have two controls in the template…(0) is the first one for display and the (1) is used for edit.
2. Modify the UpdateCommand to get data from the edit (1) control.

13. Adding Rows.
A. To the grid adding and editing are the same.
B. Just bind the control to a blank datasource and set an “AddMode” flag so you know to use the Insert instead of Update SQL.
C. Create a blank table with same structure and append a new blank row
1. dt = ds.Tables(0).Clone
2. dr = dt.NewRow
3. dt.Rows.Add(dr)
D. Then tell the table to edit the first row (new row) and bind
1. grid.EditItemIndex = 0 ‘first row
2. grid.Datasource = dt
3. grid.DataBind
4. Session(“AddMode”)=True
14. Deleting Rows (Northwind will not let you delete due to referential integrity rules…but this is how you do it.
A. Clicking on the Delete calls _DeleteCommand
1. Get the ID of the one to delete with e.Item.Cells(2).text where the 3rd column has the ID in it.
2. Now build the SQL Statement
3. Delete from table where ID = var
4. Execute the SQL
B. Clean up
1. Turn off Editing
a) Grid.EditItemIndex = -1
b) Call gridload