Skip to content

Commit b51134d

Browse files
authored
Initial ListView control with data read features (#2)
* Initial data read operations completed with SelectMethod and ModelBinding
1 parent 42eb1d0 commit b51134d

20 files changed

Lines changed: 500 additions & 81 deletions

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# BlazorWebFormsComponents
22
A collection of Blazor components that emulate the web forms components of the same name
33

4+
[![Build status](https://dev.azure.com/FritzAndFriends/BlazorWebFormsComponents/_apis/build/status/BlazorWebFormsComponents-.NET%20Standard-CI)](https://dev.azure.com/FritzAndFriends/BlazorWebFormsComponents/_build/latest?definitionId=14)
5+
46
## Controls proposed to be migrated
57
There are a significant number of controls in ASP.NET Web Forms, and we will focus on creating components in the following order:
68

samples/BeforeWebForms/BeforeWebForms.csproj

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
<WarningLevel>4</WarningLevel>
4545
</PropertyGroup>
4646
<ItemGroup>
47+
<Reference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
48+
<HintPath>..\..\src\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll</HintPath>
49+
</Reference>
4750
<Reference Include="Microsoft.CSharp" />
4851
<Reference Include="System.ComponentModel.DataAnnotations" />
4952
<Reference Include="System" />
@@ -99,18 +102,14 @@
99102
<HintPath>..\..\src\packages\Microsoft.AspNet.FriendlyUrls.Core.1.0.2\lib\net45\Microsoft.AspNet.FriendlyUrls.dll</HintPath>
100103
</Reference>
101104
</ItemGroup>
102-
<ItemGroup>
103-
<Reference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform">
104-
<HintPath>..\..\src\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll</HintPath>
105-
</Reference>
106-
</ItemGroup>
107105
<ItemGroup>
108106
<Content Include="Content\bootstrap-theme.css" />
109107
<Content Include="Content\bootstrap-theme.min.css" />
110108
<Content Include="Content\bootstrap.css" />
111109
<Content Include="Content\bootstrap.min.css" />
112110
<Content Include="Content\Site.css" />
113111
<Content Include="ControlSamples\ListView\Default.aspx" />
112+
<Content Include="ControlSamples\ListView\ModelBinding.aspx" />
114113
<Content Include="Default.aspx" />
115114
<Content Include="favicon.ico" />
116115
<Content Include="fonts\glyphicons-halflings-regular.svg" />
@@ -168,6 +167,13 @@
168167
<Compile Include="ControlSamples\ListView\Default.aspx.designer.cs">
169168
<DependentUpon>Default.aspx</DependentUpon>
170169
</Compile>
170+
<Compile Include="ControlSamples\ListView\ModelBinding.aspx.cs">
171+
<DependentUpon>ModelBinding.aspx</DependentUpon>
172+
<SubType>ASPXCodeBehind</SubType>
173+
</Compile>
174+
<Compile Include="ControlSamples\ListView\ModelBinding.aspx.designer.cs">
175+
<DependentUpon>ModelBinding.aspx</DependentUpon>
176+
</Compile>
171177
<Compile Include="Default.aspx.cs">
172178
<DependentUpon>Default.aspx</DependentUpon>
173179
<SubType>ASPXCodeBehind</SubType>
@@ -250,8 +256,8 @@
250256
<PropertyGroup>
251257
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
252258
</PropertyGroup>
253-
<Error Condition="!Exists('..\..\src\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\src\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
254259
<Error Condition="!Exists('..\..\src\packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\src\packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets'))" />
260+
<Error Condition="!Exists('..\..\src\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\src\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
255261
</Target>
256262
<Import Project="..\..\src\packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets" Condition="Exists('..\..\src\packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets')" />
257263
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

samples/BeforeWebForms/ControlSamples/ListView/Default.aspx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@
44

55
<h2>ListView control homepage</h2>
66

7+
<div>
8+
Other usage samples: <a href="ModelBinding.aspx">ModelBinding Sample</a>
9+
</div>
10+
711
<p>Here is a simple listview bound to a collection of widgets.</p>
812

9-
<asp:ListView ID="simpleListView" runat="server" ItemType="SharedSampleObjects.Models.Widget">
13+
<asp:ListView ID="simpleListView"
14+
runat="server"
15+
Enabled="true"
16+
ItemType="SharedSampleObjects.Models.Widget">
1017
<LayoutTemplate>
1118
<table>
1219
<thead>
@@ -22,6 +29,14 @@
2229
</tbody>
2330
</table>
2431
</LayoutTemplate>
32+
<AlternatingItemTemplate>
33+
<tr class="table-dark">
34+
<td><%# Item.Id %></td>
35+
<td><%# Item.Name %></td>
36+
<td><%# Item.Price.ToString("c") %></td>
37+
<td><%# Item.LastUpdate.ToString("d") %></td>
38+
</tr>
39+
</AlternatingItemTemplate>
2540
<ItemTemplate>
2641
<tr>
2742
<td><%# Item.Id %></td>
@@ -30,6 +45,17 @@
3045
<td><%# Item.LastUpdate.ToString("d") %></td>
3146
</tr>
3247
</ItemTemplate>
48+
<ItemSeparatorTemplate>
49+
<tr>
50+
<td colspan="4" style="border-bottom: 1px solid black;">&nbsp;</td>
51+
</tr>
52+
</ItemSeparatorTemplate>
53+
<EmptyDataTemplate>
54+
<tr>
55+
<td colspan="4">No widgets available</td>
56+
</tr>
57+
</EmptyDataTemplate>
58+
<EmptyItemTemplate></EmptyItemTemplate>
3359
</asp:ListView>
3460

3561
<code>&lt;table&gt;<br />

samples/BeforeWebForms/ControlSamples/ListView/Default.aspx.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ protected void Page_Load(object sender, EventArgs e)
1818
simpleListView.DataBind();
1919

2020
}
21+
2122
}
2223
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ModelBinding.aspx.cs" Inherits="BeforeWebForms.ControlSamples.ListView.ModelBinding" MasterPageFile="~/Site.Master" %>
2+
3+
<asp:Content runat="server" ContentPlaceHolderID="MainContent">
4+
5+
<h2>ListView ModelBinding Sample</h2>
6+
7+
<p>Here is a listview using ModelBinding to interact with widgets.</p>
8+
9+
<asp:ListView ID="simpleListView"
10+
runat="server"
11+
SelectMethod="simpleListView_GetData"
12+
ItemType="SharedSampleObjects.Models.Widget">
13+
<LayoutTemplate>
14+
<table>
15+
<thead>
16+
<tr>
17+
<td>Id</td>
18+
<td>Name</td>
19+
<td>Price</td>
20+
<td>Last Update</td>
21+
</tr>
22+
</thead>
23+
<tbody>
24+
<tr runat="server" id="itemPlaceHolder"></tr>
25+
</tbody>
26+
</table>
27+
</LayoutTemplate>
28+
<AlternatingItemTemplate>
29+
<tr class="table-dark">
30+
<td><%# Item.Id %></td>
31+
<td><%# Item.Name %></td>
32+
<td><%# Item.Price.ToString("c") %></td>
33+
<td><%# Item.LastUpdate.ToString("d") %></td>
34+
</tr>
35+
</AlternatingItemTemplate>
36+
<ItemTemplate>
37+
<tr>
38+
<td><%# Item.Id %></td>
39+
<td><%# Item.Name %></td>
40+
<td><%# Item.Price.ToString("c") %></td>
41+
<td><%# Item.LastUpdate.ToString("d") %></td>
42+
</tr>
43+
</ItemTemplate>
44+
<ItemSeparatorTemplate>
45+
<tr>
46+
<td colspan="4" style="border-bottom: 1px solid black;">&nbsp;</td>
47+
</tr>
48+
</ItemSeparatorTemplate>
49+
<EmptyDataTemplate>
50+
<tr>
51+
<td colspan="4">No widgets available</td>
52+
</tr>
53+
</EmptyDataTemplate>
54+
<EmptyItemTemplate></EmptyItemTemplate>
55+
</asp:ListView>
56+
57+
58+
</asp:Content>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using SharedSampleObjects.Models;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Web;
6+
using System.Web.UI;
7+
using System.Web.UI.WebControls;
8+
9+
namespace BeforeWebForms.ControlSamples.ListView
10+
{
11+
public partial class ModelBinding : System.Web.UI.Page
12+
{
13+
protected void Page_Load(object sender, EventArgs e)
14+
{
15+
16+
}
17+
18+
// The return type can be changed to IEnumerable, however to support
19+
// paging and sorting, the following parameters must be added:
20+
// int maximumRows
21+
// int startRowIndex
22+
// out int totalRowCount
23+
// string sortByExpression
24+
public IQueryable<Widget> simpleListView_GetData()
25+
{
26+
return Widget.SimpleWidgetList.AsQueryable();
27+
}
28+
}
29+
}

samples/BeforeWebForms/ControlSamples/ListView/ModelBinding.aspx.designer.cs

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/BeforeWebForms/Web.config

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
<system.web>
88
<compilation debug="true" targetFramework="4.8">
99
<assemblies>
10-
<add assembly="netstandard, Version=2.0.3.0, Culture=neutral,
11-
PublicKeyToken=cc7b13ffcd2ddd51"/>
10+
<add assembly="netstandard, Version=2.0.3.0, Culture=neutral, &#xD;&#xA; PublicKeyToken=cc7b13ffcd2ddd51" />
1211
</assemblies>
1312
</compilation>
1413
<httpRuntime targetFramework="4.8" />

src/AfterBlazorServerSide/Pages/ControlSamples/ListView/Index.razor

Lines changed: 61 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,74 @@
22

33
<h2>ListView Component homepage</h2>
44

5+
<div>
6+
Other usage samples: <a href="./ControlSamples/ListView/ModelBinding">ModelBinding Sample</a>
7+
</div>
8+
59
<p>Here is a simple listview bound to a collection of widgets.</p>
610

7-
<ListView ID="simpleListView"
8-
runat="server"
9-
ItemType="SharedSampleObjects.Models.Widget"
10-
Items="Widget.SimpleWidgetList">
11-
<LayoutTemplate>
12-
<table>
13-
<thead>
14-
<tr>
15-
<td>Id</td>
16-
<td>Name</td>
17-
<td>Price</td>
18-
<td>Last Update</td>
19-
</tr>
20-
</thead>
21-
<tbody>
22-
<tr runat="server" id="itemPlaceHolder"></tr>
23-
</tbody>
24-
</table>
25-
</LayoutTemplate>
26-
<ItemTemplate Context="Item">
27-
<tr>
28-
<td>@Item.Id</td>
29-
<td>@Item.Name</td>
30-
<td>@Item.Price.ToString("c")</td>
31-
<td>@Item.LastUpdate.ToString("d")</td>
32-
</tr>
33-
</ItemTemplate>
34-
</ListView>
11+
<table class="table">
12+
<thead>
13+
<tr>
14+
<td>Id</td>
15+
<td>Name</td>
16+
<td>Price</td>
17+
<td>Last Update</td>
18+
</tr>
19+
</thead>
20+
<tbody>
21+
<ListView @ref="simpleListView"
22+
runat="server"
23+
EnableViewState="false"
24+
Context="Item"
25+
ItemType="SharedSampleObjects.Models.Widget">
26+
<AlternatingItemTemplate>
27+
<tr class="table-dark">
28+
<td>@Item.Id</td>
29+
<td>@Item.Name</td>
30+
<td>@Item.Price.ToString("c")</td>
31+
<td>@Item.LastUpdate.ToString("d")</td>
32+
</tr>
33+
</AlternatingItemTemplate>
34+
<ItemTemplate>
35+
<tr>
36+
<td>@Item.Id</td>
37+
<td>@Item.Name</td>
38+
<td>@Item.Price.ToString("c")</td>
39+
<td>@Item.LastUpdate.ToString("d")</td>
40+
</tr>
41+
</ItemTemplate>
42+
<ItemSeparatorTemplate>
43+
@*<tr>
44+
<td colspan="4" style="border-bottom: 1px solid black;">&nbsp;</td>
45+
</tr>*@
46+
</ItemSeparatorTemplate>
47+
<EmptyDataTemplate>
48+
<tr>
49+
<td colspan="4">No widgets available</td>
50+
</tr>
51+
</EmptyDataTemplate>
52+
</ListView>
53+
</tbody>
54+
</table>
3555

3656
@code {
3757

38-
override void OnInitialized()
39-
{
58+
BlazorWebFormsComponents.ListView<Widget> simpleListView { get; set; }
59+
60+
protected override void OnAfterRender(bool firstRender)
61+
{
62+
63+
if (firstRender)
64+
{
65+
simpleListView.DataSource = Widget.SimpleWidgetList;
66+
simpleListView.DataBind();
67+
}
4068

41-
69+
//base.OnParametersSet();
70+
base.OnAfterRender(firstRender);
4271

43-
base.OnInitialized();
44-
}
72+
}
4573

4674
}
4775

0 commit comments

Comments
 (0)