“digging into advanced features of the asp.net datagrid ... · webinar series 2003 speakers –...
TRANSCRIPT
Copyright © 2002. Iron Speed Inc. All rights reserved
“Digging into Advanced Features of the ASP.NET DataGrid Control” Webinar
Trouble connecting to audio? Let us know by using the “Questions” feature on the left side of this window.
Presenters:
Paul Litwin Alan Fisher
Audio access: 1–800-261-3225 Or 1-972-512-0695.Passcode: 989 5485#
2
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Webinar Essentials
PlaceWare Attendee Features:
Feedback to Presenter
Questions for Presenter
“Expanded View” button
Help: 1-800-893-8779 or 1-971-544-3222
If your webinar window closes, use your “Re-enter” meeting browser window
3
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Speakers – Paul Litwin
Co-Founder, Senior Trainer, Deep Training(www.deeptraining.com)
Developer: ASP.NET, ASP, VB, SQLServer, Access
MCSD
Microsoft MVP
Chair, Microsoft ASP.NET Connections
Leader of Web Meeting, .NETDeveloper’s Association
Author of several developer’sbooks on ASP.NET, Access
E-mail: [email protected]
4
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Speakers – Paul Litwin & Alan Fisher.NET Consultant, Trainer andEvangelist
Principal at Deep Training andLitwin Consulting
Author, Conference Chair
Co-founder, CTO of Onsale, the first online ecommerce auction
Developed several large, mission critical enterprise web applications
Author of the first book on CASE
Co-founder and Chairman, Iron Speed
5
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Raffle Items
“Written for developers and full of practical shortcuts.”
ASP.NET For Developers teaches ASP.NET using Visual Basic.NET in the most concise, straightforward
manner possible.
6
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Raffle Items
One developer seat
One year product support
A $4,500 software value
7
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Special Offers for Attendees
Post-event invitations
Training discounts from Deep Training
Free evaluation of Iron Speed Designer
Samples and slides from this webinar
Watch for your offers via email later today
8
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Digging into Advanced Features of the ASP.NET DataGrid Control
Paul Litwin.NET trainer and author
Co-founder and Senior trainer,Deep Training
9
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Objectives
Learn how to sort columns in a grid in both ascending and descending order
Learn how to use automatic and custom paging
Learn how to use templated columns
10
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Agenda
Sorting it Out
Pagination
Template Columns
11
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Sorting Grids
Steps to provide sorting
1. AllowSorting = “True”
2. Provide sorting event handler that retrieves sort expression (name of sort column)
3. Sort data based on sort expression
12
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Simple Sort Example: SortedGrid1.aspx
Private Sub dgrCustomers_SortCommand(source As Object, _e As DataGridSortCommandEventArgs) Call BindDataGrid(e.SortExpression)
End Sub
Sub BindDataGrid(ByVal strSort As String)...
' Customize sort order based on strSortDim strSQL As String = _"SELECT CustomerID, CompanyName, ContactName, " & _"Country FROM Customers " & _"ORDER BY " & strSort
...
Private Sub dgrCustomers_SortCommand(source As Object, _e As DataGridSortCommandEventArgs) Call BindDataGrid(e.SortExpression)
End Sub
Sub BindDataGrid(ByVal strSort As String)...
' Customize sort order based on strSortDim strSQL As String = _"SELECT CustomerID, CompanyName, ContactName, " & _"Country FROM Customers " & _"ORDER BY " & strSort
...
13
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Ascending/Descending Sorts
Need to store away sort column and direction between postbacks
Use ViewState
14
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Ascending/Descending Sort ExampleSortedGrid2.aspx – rebuilds DataReader each time
Private Sub dgrCustomers_SortCommand(…) If ViewState("SortCol") = e.SortExpression Then
If ViewState("SortDir") = "ASC" ThenViewState("SortDir") = "DESC"
ElseViewState("SortDir") = "ASC"
End IfElse
ViewState("SortDir") = "ASC"End IfViewState("SortCol") = e.SortExpressionCall BindDataGrid()
End SubSub BindDataGrid()
…Dim strSQL As String = _
"SELECT CustomerID, CompanyName, ContactName, " & _"Country FROM Customers "
If Not ViewState("SortCol") Is Nothing ThenstrSQL &= "ORDER BY " & ViewState("SortCol") & " " & _ViewState("SortDir")
End If...
Private Sub dgrCustomers_SortCommand(…) If ViewState("SortCol") = e.SortExpression Then
If ViewState("SortDir") = "ASC" ThenViewState("SortDir") = "DESC"
ElseViewState("SortDir") = "ASC"
End IfElse
ViewState("SortDir") = "ASC"End IfViewState("SortCol") = e.SortExpressionCall BindDataGrid()
End SubSub BindDataGrid()
…Dim strSQL As String = _
"SELECT CustomerID, CompanyName, ContactName, " & _"Country FROM Customers "
If Not ViewState("SortCol") Is Nothing ThenstrSQL &= "ORDER BY " & ViewState("SortCol") & " " & _ViewState("SortDir")
End If...
15
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Ascending/Descending Sort ExampleSortedGrid3.aspx – caches DataView in Session
Private Sub dgrCustomers_SortCommand(…) If ViewState("SortCol") = e.SortExpression Then
If ViewState("SortDir") = "ASC" ThenViewState("SortDir") = "DESC"
ElseViewState("SortDir") = "ASC"
End IfElse
ViewState("SortDir") = "ASC"End IfViewState("SortCol") = e.SortExpression
CType(Session("dvCustomer"), DataView).Sort = _ViewState("SortCol") & " " & ViewState("SortDir")
Call BindDataGrid()End Sub
Private Sub dgrCustomers_SortCommand(…) If ViewState("SortCol") = e.SortExpression Then
If ViewState("SortDir") = "ASC" ThenViewState("SortDir") = "DESC"
ElseViewState("SortDir") = "ASC"
End IfElse
ViewState("SortDir") = "ASC"End IfViewState("SortCol") = e.SortExpression
CType(Session("dvCustomer"), DataView).Sort = _ViewState("SortCol") & " " & ViewState("SortDir")
Call BindDataGrid()End Sub
16
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Agenda
Sorting it Out
Pagination
Template Columns
17
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Pagination
Properties related to pagination
AllowPaging
AllowCustomPaging
PageSize
PagerStyle-Mode (NextPrev or NumericPages)
PagerStyle-Position (Top, Bottom, TopAndBottom)
PagerStyle-PageButtonCount
…
18
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Automatic Pagination
AllowPaging = "True"
You provide DataGrid with data source and a PageSize and it takes care of chopping up data into pages and displaying the correct page
Very little coding on your part
Requires query to be re-run for every page unless you cache the data source somewhere
19
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Pagination ExamplesCustomersPageAuto1.aspx – rebuilds DataReader each timeCustomersPageAuto2.aspx – caches DataSet in Session
<asp:DataGrid id="dgrCustomers" runat="server"...AllowPaging="True"PageSize="10"PagerStyle-Mode="NumericPages"PagerStyle-HorizontalAlign="Left">
</asp:DataGrid>
Private Sub dgrCustomers_PageIndexChanged(source As Object, _e As DataGridPageChangedEventArgs) dgrCustomers.CurrentPageIndex = e.NewPageIndexCall BindDataGrid()
End Sub
<asp:DataGrid id="dgrCustomers" runat="server"...AllowPaging="True"PageSize="10"PagerStyle-Mode="NumericPages"PagerStyle-HorizontalAlign="Left">
</asp:DataGrid>
Private Sub dgrCustomers_PageIndexChanged(source As Object, _e As DataGridPageChangedEventArgs) dgrCustomers.CurrentPageIndex = e.NewPageIndexCall BindDataGrid()
End Sub
20
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Custom Pagination
AllowPaging = "True"
AllowCustomPaging = "True"
You provide DataGrid with each page of data
More coding than automatic paging
21
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Custom Pagination, Solution #1
How do you split up data into pages and grab correct page?
Solution #1: Use arbitrarily-divided evenly-sized pages
Use db-specific SQL (temp tables, cursors, etc.)
Example:
CustomersPageCustom1.aspx
Uses procGetCustomersPage stored proc & SQL Server temp tables
22
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Arbitrarily-Divided Pages ExampleCustomersPageCustom1.aspx – code
Function GetPage(intPageSize As Integer, intPageIndex As Integer) As SqlDataReaderDim strCnx As String = "server=localhost;uid=sa;pwd=;database=northwind;"Dim prm As SqlParameter
Dim cnx As SqlConnection = New SqlConnection(strCnx)cnx.Open()
Dim cmd As SqlCommand = New SqlCommand("procGetCustomersPage", cnx)cmd.CommandType = CommandType.StoredProcedure
' Create parameters…
Dim sdr As SqlDataReadersdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Return sdrEnd Function
Private Sub dgrCustomers_PageIndexChanged(source As Object, e As DataGridPageChangedEventArgs)dgrCustomers.CurrentPageIndex = e.NewPageIndexdgrCustomers.DataSource = GetPage(dgrCustomers.PageSize, e.NewPageIndex)dgrCustomers.DataBind()
End Sub
Function GetPage(intPageSize As Integer, intPageIndex As Integer) As SqlDataReaderDim strCnx As String = "server=localhost;uid=sa;pwd=;database=northwind;"Dim prm As SqlParameter
Dim cnx As SqlConnection = New SqlConnection(strCnx)cnx.Open()
Dim cmd As SqlCommand = New SqlCommand("procGetCustomersPage", cnx)cmd.CommandType = CommandType.StoredProcedure
' Create parameters…
Dim sdr As SqlDataReadersdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Return sdrEnd Function
Private Sub dgrCustomers_PageIndexChanged(source As Object, e As DataGridPageChangedEventArgs)dgrCustomers.CurrentPageIndex = e.NewPageIndexdgrCustomers.DataSource = GetPage(dgrCustomers.PageSize, e.NewPageIndex)dgrCustomers.DataBind()
End SubView
23
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Function GetPage(intPageSize As Integer, intPageIndex As Integer) As SqlDataReaderDim strCnx As String = "server=localhost;uid=sa;pwd=;database=northwind;"Dim prm As SqlParameter
Dim cnx As SqlConnection = New SqlConnection(strCnx)cnx.Open()
Dim cmd As SqlCommand = New SqlCommand("procGetCustomersPage", cnx)cmd.CommandType = CommandType.StoredProcedure
' Create parameters…
Dim sdr As SqlDataReadersdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Return sdrEnd Function
Private Sub dgrCustomers_PageIndexChanged(source As Object, e As DataGridPageChangedEventArgs)
dgrCustomers.CurrentPageIndex = e.NewPageIndexdgrCustomers.DataSource = GetPage(dgrCustomers.PageSize, e.NewPageIndex)dgrCustomers.DataBind()
End Sub
Function GetPage(intPageSize As Integer, intPageIndex As Integer) As SqlDataReaderDim strCnx As String = "server=localhost;uid=sa;pwd=;database=northwind;"Dim prm As SqlParameter
Dim cnx As SqlConnection = New SqlConnection(strCnx)cnx.Open()
Dim cmd As SqlCommand = New SqlCommand("procGetCustomersPage", cnx)cmd.CommandType = CommandType.StoredProcedure
' Create parameters…
Dim sdr As SqlDataReadersdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Return sdrEnd Function
Private Sub dgrCustomers_PageIndexChanged(source As Object, e As DataGridPageChangedEventArgs)
dgrCustomers.CurrentPageIndex = e.NewPageIndexdgrCustomers.DataSource = GetPage(dgrCustomers.PageSize, e.NewPageIndex)dgrCustomers.DataBind()
End Sub
24
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Arbitrarily-Divided Pages Example CustomersPageCustom1.aspx – stored proc
ALTER PROCEDURE procGetCustomersPage( @pageSize int, @pageIndex int )ASDECLARE @PageLowerBound intDECLARE @PageUpperBound intSET @PageLowerBound = @pageSize * @pageIndexSET @PageUpperBound = @pageLowerBound + @pageSize + 1-- Create a temp table to store the select resultsCREATE TABLE #PageIndex ( IndexId int IDENTITY (1, 1) NOT NULL, PageId NCHAR(5) )BEGIN-- INSERT into the temp tableINSERT INTO #PageIndex (PageId)SELECT CustomerIDFROM Customers ORDER BY CustomerID-- Get the CustomersSELECT CustomerID, CompanyName, ContactName, CountryFROM Customers WITH (nolock)
JOIN #PageIndex WITH (nolock) ON CustomerID = PageID
WHERE IndexID > @PageLowerBound ANDIndexID < @PageUpperBound
ORDER BY IndexIDEnd
ALTER PROCEDURE procGetCustomersPage( @pageSize int, @pageIndex int )ASDECLARE @PageLowerBound intDECLARE @PageUpperBound intSET @PageLowerBound = @pageSize * @pageIndexSET @PageUpperBound = @pageLowerBound + @pageSize + 1-- Create a temp table to store the select resultsCREATE TABLE #PageIndex ( IndexId int IDENTITY (1, 1) NOT NULL, PageId NCHAR(5) )BEGIN-- INSERT into the temp tableINSERT INTO #PageIndex (PageId)SELECT CustomerIDFROM Customers ORDER BY CustomerID-- Get the CustomersSELECT CustomerID, CompanyName, ContactName, CountryFROM Customers WITH (nolock)
JOIN #PageIndex WITH (nolock) ON CustomerID = PageID
WHERE IndexID > @PageLowerBound ANDIndexID < @PageUpperBound
ORDER BY IndexIDEnd
View
25
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
ALTER PROCEDURE procGetCustomersPage( @pageSize int, @pageIndex int )ASDECLARE @PageLowerBound intDECLARE @PageUpperBound intSET @PageLowerBound = @pageSize * @pageIndexSET @PageUpperBound = @pageLowerBound + @pageSize + 1-- Create a temp table to store the select resultsCREATE TABLE #PageIndex ( IndexId int IDENTITY (1, 1) NOT NULL, PageIdNCHAR(5) )BEGIN-- INSERT into the temp tableINSERT INTO #PageIndex (PageId)SELECT CustomerIDFROM Customers ORDER BY CustomerID-- Get the CustomersSELECT CustomerID, CompanyName, ContactName, CountryFROM Customers WITH (nolock)
JOIN #PageIndex WITH (nolock) ON CustomerID = PageID
WHERE IndexID > @PageLowerBound ANDIndexID < @PageUpperBound
ORDER BY IndexIDEnd
ALTER PROCEDURE procGetCustomersPage( @pageSize int, @pageIndex int )ASDECLARE @PageLowerBound intDECLARE @PageUpperBound intSET @PageLowerBound = @pageSize * @pageIndexSET @PageUpperBound = @pageLowerBound + @pageSize + 1-- Create a temp table to store the select resultsCREATE TABLE #PageIndex ( IndexId int IDENTITY (1, 1) NOT NULL, PageIdNCHAR(5) )BEGIN-- INSERT into the temp tableINSERT INTO #PageIndex (PageId)SELECT CustomerIDFROM Customers ORDER BY CustomerID-- Get the CustomersSELECT CustomerID, CompanyName, ContactName, CountryFROM Customers WITH (nolock)
JOIN #PageIndex WITH (nolock) ON CustomerID = PageID
WHERE IndexID > @PageLowerBound ANDIndexID < @PageUpperBound
ORDER BY IndexIDEnd
26
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Custom Pagination, Solution #2
How do you split up data into pages and grab correct page?
Solution #2: Use data-dependent unevenly-sized pages
Use an existing column to split up pages
Example:
CustomersPageCustom2.aspx
Uses CompanyName LIKE "A*" expression
Requires use of ItemCreated event handler to fix up pager
27
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Data-Dependent Pages ExampleCustomersPageCustom2.aspx – code 1 of 2
Function GetPage(ByVal intPageIndex As Integer) As SqlDataReaderDim strCnx As String = "server=localhost;uid=sa;pwd=;database=northwind;"Dim strSQL = "SELECT CustomerID, CompanyName, ContactName, Country " & _
"FROM Customers " & _"WHERE CompanyName LIKE '" & Chr(intPageIndex + Asc("A")) & "%' " & _"ORDER BY CompanyName "
Dim cnx As SqlConnection = New SqlConnection(strCnx)cnx.Open()
Dim cmd As SqlCommand = New SqlCommand(strSQL, cnx)cmd.CommandType = CommandType.Text
Dim sdr As SqlDataReadersdr = cmd.ExecuteReader()
Return sdrEnd Function
Private Sub dgrCustomers_PageIndexChanged(source As Object, e As DataGridPageChangedEventArgs)dgrCustomers.CurrentPageIndex = e.NewPageIndexdgrCustomers.DataSource = GetPage(e.NewPageIndex)dgrCustomers.DataBind()
End Sub
Function GetPage(ByVal intPageIndex As Integer) As SqlDataReaderDim strCnx As String = "server=localhost;uid=sa;pwd=;database=northwind;"Dim strSQL = "SELECT CustomerID, CompanyName, ContactName, Country " & _
"FROM Customers " & _"WHERE CompanyName LIKE '" & Chr(intPageIndex + Asc("A")) & "%' " & _"ORDER BY CompanyName "
Dim cnx As SqlConnection = New SqlConnection(strCnx)cnx.Open()
Dim cmd As SqlCommand = New SqlCommand(strSQL, cnx)cmd.CommandType = CommandType.Text
Dim sdr As SqlDataReadersdr = cmd.ExecuteReader()
Return sdrEnd Function
Private Sub dgrCustomers_PageIndexChanged(source As Object, e As DataGridPageChangedEventArgs)dgrCustomers.CurrentPageIndex = e.NewPageIndexdgrCustomers.DataSource = GetPage(e.NewPageIndex)dgrCustomers.DataBind()
End Sub
28
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003Data-Dependent Pages ExampleCustomersPageCustom2.aspx – code 2 of 2
Private Sub dgrCustomers_ItemCreated(sender As Object, e As DataGridItemEventArgs) Dim lit As ListItemType = e.Item.ItemTypeDim intI As Integer
If lit = ListItemType.Pager ThenDim pgr As TableCell = e.Item.Controls(0)
For intI = 0 To pgr.Controls.Count - 1Dim ctl As Object = pgr.Controls(intI)
If TypeOf ctl Is LinkButton Then' LinkButton control represents other pagesDim lbt As LinkButton = CType(pgr.Controls(intI), LinkButton)
If CType(ctl, LinkButton).Text <> "..." Thenlbt.Text = "| " & Chr(Convert.ToInt32(lbt.Text) + Asc("A") - 1) & " |"
End IfElseIf TypeOf ctl Is Label Then
' Label control represents current pageDim lbl As Label = CType(pgr.Controls(intI), Label)lbl.Text = "| " & Chr(Convert.ToInt32(lbl.Text) + Asc("A") - 1) & " |"lbl.BackColor = Color.SkyBluelbl.Font.Bold = True
End IfNext intI
End IfEnd Sub
Private Sub dgrCustomers_ItemCreated(sender As Object, e As DataGridItemEventArgs) Dim lit As ListItemType = e.Item.ItemTypeDim intI As Integer
If lit = ListItemType.Pager ThenDim pgr As TableCell = e.Item.Controls(0)
For intI = 0 To pgr.Controls.Count - 1Dim ctl As Object = pgr.Controls(intI)
If TypeOf ctl Is LinkButton Then' LinkButton control represents other pagesDim lbt As LinkButton = CType(pgr.Controls(intI), LinkButton)
If CType(ctl, LinkButton).Text <> "..." Thenlbt.Text = "| " & Chr(Convert.ToInt32(lbt.Text) + Asc("A") - 1) & " |"
End IfElseIf TypeOf ctl Is Label Then
' Label control represents current pageDim lbl As Label = CType(pgr.Controls(intI), Label)lbl.Text = "| " & Chr(Convert.ToInt32(lbl.Text) + Asc("A") - 1) & " |"lbl.BackColor = Color.SkyBluelbl.Font.Bold = True
End IfNext intI
End IfEnd Sub
29
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Agenda
Sorting it Out
Pagination
Template Columns
30
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
When to Use Template Column?
If you need to do something that is not provided by standard DataGrid columns
Problem: Need to link to another page but querystring may contain special characters
Try using CustomerMain.aspx with Netscape and a CustomerId containing a space
Solution: Use TemplateColumn that calls Server.UrlEncode to encode querystring
CustomerMain_Template.aspx
31
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
TemplateColumn Example – Encoding querystringCustomerMain_Template.aspx
<asp:TemplateColumn HeaderText="Customer"><itemtemplate>
<asp:LabelText='<%# CreateLinkCol(Container.DataItem("CustomerId"),
Container.DataItem("CompanyName")) %>' runat="server"/>
</ItemTemplate></asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Customer"><itemtemplate>
<asp:LabelText='<%# CreateLinkCol(Container.DataItem("CustomerId"),
Container.DataItem("CompanyName")) %>' runat="server"/>
</ItemTemplate></asp:TemplateColumn>
Function CreateLinkCol(ByVal strId, ByVal strName) As String' Create hyperlink with encoded querystring' to handle special chars in IdReturn "<a href=""CustomerEdit_TemplateCol.aspx?Customer=" & _Server.UrlEncode(strId) & """>" & strName & "</a>"
End Function
Function CreateLinkCol(ByVal strId, ByVal strName) As String' Create hyperlink with encoded querystring' to handle special chars in IdReturn "<a href=""CustomerEdit_TemplateCol.aspx?Customer=" & _Server.UrlEncode(strId) & """>" & strName & "</a>"
End Function
32
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
When to Use Template Column?
If you need to do something that is not provided by standard DataGrid columns
Problem: Would like user to be able to use a dropdownlist control when editing within a grid
Solution: Use TemplateColumn
DataGridWithDropDown.aspx
33
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
DropDownList ExampleDataGridWithDropDown.aspx– HTML
<asp:templatecolumn headertext="Title"><itemtemplate>
<%# Container.DataItem("Title")%></itemtemplate><edititemtemplate>
<asp:dropdownlistid="drpTitle" datatextfield="Title" datavaluefield="Title" datasource="<%#GetTitlesDataSource()%>" selectedindex='<%#GetTitlesSelectedIndex(Container.DataItem("Title"))%>' runat="server"/>
</edititemtemplate></asp:templatecolumn>
<asp:templatecolumn headertext="Title"><itemtemplate>
<%# Container.DataItem("Title")%></itemtemplate><edititemtemplate>
<asp:dropdownlistid="drpTitle" datatextfield="Title" datavaluefield="Title" datasource="<%#GetTitlesDataSource()%>" selectedindex='<%#GetTitlesSelectedIndex(Container.DataItem("Title"))%>' runat="server"/>
</edititemtemplate></asp:templatecolumn>
34
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
DropDownList ExampleDataGridWithDropDown.aspx– GetTitlesDataSource function
Public Function GetTitlesDataSource() As DataView'Provide DataSource to Title column's EditItemTemplateReturn ds.Tables("EmployeeTitles").DefaultView
End Function
Public Function GetTitlesDataSource() As DataView'Provide DataSource to Title column's EditItemTemplateReturn ds.Tables("EmployeeTitles").DefaultView
End Function
35
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
DropDownList ExampleDataGridWithDropDown.aspx– GetTitlesSelectedIndex function
Public Function GetTitlesSelectedIndex(ByVal objItem As Object) _As Integer
'Provide Initial SelectedIndex to Title column's EditItemTemplateDim intI = 0Dim dtEmpTitles As DataTable = ds.Tables("EmployeeTitles")Dim drEmpTitles As DataRow' Handle null valuesIf objItem Is System.DBNull.Value Then
objItem = "(none)"End If' Iterate through Title rows to locate matching item. ' When a match is found, intI will be SelectedIndex.For Each drEmpTitles In dtEmpTitles.Rows
If objItem = drEmpTitles("Title") ThenReturn intI
End IfintI = intI + 1
NextEnd Function
Public Function GetTitlesSelectedIndex(ByVal objItem As Object) _As Integer
'Provide Initial SelectedIndex to Title column's EditItemTemplateDim intI = 0Dim dtEmpTitles As DataTable = ds.Tables("EmployeeTitles")Dim drEmpTitles As DataRow' Handle null valuesIf objItem Is System.DBNull.Value Then
objItem = "(none)"End If' Iterate through Title rows to locate matching item. ' When a match is found, intI will be SelectedIndex.For Each drEmpTitles In dtEmpTitles.Rows
If objItem = drEmpTitles("Title") ThenReturn intI
End IfintI = intI + 1
NextEnd Function
36
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Summary
We looked at how to sort columns in a grid in both ascending and descending order
We learned how to use automatic pagination
We learned how to employ custom pagination, both with arbitrarily-divided and data-divided pages
We learned how to use templated columns to provide encoding of querystrings and editable dropdownlist controls
37
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
ASP.NET ResourcesWeb Sites
Microsoftasp.net, gotdotnet.com, msdn.microsoft.com
Third-partyaspalliance.com, angrycoder.com, dotnetjunkies.com, 4guysfromrolla.com, dotnetwire.com, deeptraining.com
Web Communitieswww.aspadvice.com (listserv)news.microsoft.com (newsgroups)www.asp.net forums (web based)
ConferenceMicrosoft ASP.NET Connections
www.asp-connections.com
38
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Recommended ASP.NET Books
General ASP.NET BooksASP.NET for Developers
Mike Amundsen and Paul LitwinASP.NET Unleashed
Steven WaltherASP.NET Tips, Tutorials, and Code
Mitchell, et al (SAMS)
Books with Extensive DataGrid CoverageBuilding Web Solutions with ASP.NET and ADO.NET
Dino EspositoASP.NET Data Web Controls Kick Start
Scott Mitchell
39
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Thank You!
Code samples from this webinar:
http://www.deeptraining.com/ironspeed
40
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
.NET Code Generation
Alan FisherCo-Founder and Chairman, Iron Speed, Inc.
41
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
The Application Development Bar Keeps Rising
Stateless browser environmentSQL queries are hard to write
User Interface is more complicated to build
Scalability
Consistent Security
New skills for the IT team
Users never know what theywant
42
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
What You Need: Custom, Complex Pages
Multi-table joins
Parent/Child Tables Pagination
Editable Fields
Custom Field Values
43
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Generating A Sample .NET Application
44
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
How Iron Speed Designer Works
Iron Speed Markup Language (IML) tags drive code generation
45
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Database Layer
Application Layer
Presentation Layer
Extensible 3-Tier Architecture
46
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Extensible Class HierarchyClasses for: Pages, Tables (Records), Table Joins
Safe classes can be modified, extended, and further sub-classed
Generated classes are rewritten with each regeneration
Extend applications using VB, C# or any .NET language
Add custom application logic
Integrate with external systems
Add additional validation code
47
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Back to our Generated Application…
48
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Built-in Security
Role Based Access Control
Automatic Sign-out
Data Transmission Encryption
Password Storage
Firewall Security
49
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Application Generation Comes of Age
80% of the Work in 5% of the Time
50
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Review and Questions
Paul Litwin Alan Fisher
51
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Product Briefings of Iron Speed Designer
One Hour Online Demonstrations For Webinar Attendees
Wednesday, June 18, 2003, 8:00 a.m. PST
(11:00 a.m. EST and 4:00 p.m. GMT)
Wednesday, June 25, 2003, 11:00 a.m. PST(2:00 p.m. EST)
Tuesday, July 1, 2003, 11:00 a.m. PST (2:00 p.m. EST)
Register now:
http://www.ironspeed.com/webinar
52
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Raffle ItemsAnd the winner is:
53
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Raffle Items
One developer seat
One year maintenance
A $4,500 software value
And the winner is….
54
Copyright © 2003. Iron Speed Inc. All rights reserved
Webinar Series 2003
Thank You!
Watch your email later today for special offers from Paul Litwin, Deep Training and Iron Speed.
http://www.ironspeed.com
Resources:http://www.ironspeed.com/webinarhttp://www.deeptraining.com
Copy of the slides: [email protected]
Code samples from this webinar:
http://www.deeptraining.com/ironspeed