Skip to content

Commit ad44184

Browse files
committed
Autogenerated Columns
1 parent 111983f commit ad44184

File tree

11 files changed

+200
-7
lines changed

11 files changed

+200
-7
lines changed

samples/AfterBlazorServerSide/Pages/ComponentList.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<li>DataPager </li>
99
<li>DetailsView </li>
1010
<li>FormView </li>
11-
<li><a href="/ControlSamples/GridView/Default">GridView</a></li>
11+
<li><a href="/ControlSamples/GridView">GridView</a></li>
1212
<li><a href="/ControlSamples/ListView">ListView</a></li>
1313
<li><a href="/ControlSamples/Repeater">Repeater</a></li>
1414

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
@page "/ControlSamples/GridView/AutoGeneratedColumns"
2+
3+
<h2>GridView Default AutoGeneratedColumns</h2>
4+
5+
<Nav />
6+
7+
<GridView ItemType="Customer"
8+
DataKeyNames="CustomerID"
9+
SelectMethod="GetCustomers"
10+
AutogenerateColumns="true">
11+
</GridView>
12+
13+
@code{
14+
public IQueryable<Customer> GetCustomers(int maxRows, int startRowIndex, string sortByExpression, out int totalRowCount)
15+
{
16+
var customers = new List<Customer>();
17+
var c1 = new Customer
18+
{
19+
CustomerID = 1,
20+
FirstName = "John",
21+
LastName = "Smith",
22+
CompanyName = "Virus"
23+
};
24+
25+
var c2 = new Customer
26+
{
27+
CustomerID = 2,
28+
FirstName = "Jose",
29+
LastName = "Rodriguez",
30+
CompanyName = "Boring"
31+
};
32+
33+
34+
var c3 = new Customer
35+
{
36+
CustomerID = 3,
37+
FirstName = "Jason",
38+
LastName = "Ramirez",
39+
CompanyName = "Fun Machines"
40+
};
41+
42+
customers.Add(c1);
43+
customers.Add(c2);
44+
customers.Add(c3);
45+
46+
totalRowCount = customers.Count();
47+
return customers.AsQueryable();
48+
}
49+
}

samples/AfterBlazorServerSide/Pages/ControlSamples/GridView/Default.razor

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
@page "/ControlSamples/GridView/Default"
1+
@page "/ControlSamples/GridView"
22

33
<h2>GridView Default Example</h2>
44

5-
<GridView ItemType="Customer" DataKeyNames="CustomerID" SelectMethod="GetCustomers">
5+
<Nav />
6+
7+
<GridView ItemType="Customer"
8+
AutogenerateColumns="false"
9+
DataKeyNames="CustomerID"
10+
SelectMethod="GetCustomers">
611
<Columns>
712
<BoundField DataField="CustomerID" HeaderText="ID" ItemType="Customer" />
813
<BoundField DataField="CompanyName" HeaderText="CompanyName" ItemType="Customer" />
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div>
2+
Other usage samples:
3+
<NavLink href="./ControlSamples/GridView" class="component-link" Match="NavLinkMatch.All">Simple GridView </NavLink> |
4+
<NavLink href="./ControlSamples/GridView/AutoGeneratedColumns" class="component-link" Match="NavLinkMatch.All">AutoGenerated Columns</NavLink> |
5+
</div>

samples/BeforeWebForms2/BeforeWebForms2.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
<Content Include="ControlSamples\DataList\FlowLayout.aspx" />
7070
<Content Include="ControlSamples\DataList\RepeatColumns.aspx" />
7171
<Content Include="ControlSamples\DataList\StyleAttributes.aspx" />
72+
<Content Include="ControlSamples\GridView\AutoGeneratedColumns.aspx" />
7273
<Content Include="ControlSamples\GridView\Default.aspx" />
7374
<Content Include="ControlSamples\ListView\Default.aspx" />
7475
<Content Include="ControlSamples\ListView\Grouping.aspx" />
@@ -151,6 +152,13 @@
151152
<Compile Include="ControlSamples\DataList\StyleAttributes.aspx.designer.cs">
152153
<DependentUpon>StyleAttributes.aspx</DependentUpon>
153154
</Compile>
155+
<Compile Include="ControlSamples\GridView\AutoGeneratedColumns.aspx.cs">
156+
<DependentUpon>AutoGeneratedColumns.aspx</DependentUpon>
157+
<SubType>ASPXCodeBehind</SubType>
158+
</Compile>
159+
<Compile Include="ControlSamples\GridView\AutoGeneratedColumns.aspx.designer.cs">
160+
<DependentUpon>AutoGeneratedColumns.aspx</DependentUpon>
161+
</Compile>
154162
<Compile Include="ControlSamples\GridView\Customer.cs" />
155163
<Compile Include="ControlSamples\GridView\Default.aspx.cs">
156164
<DependentUpon>Default.aspx</DependentUpon>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="AutoGeneratedColumns.aspx.cs" Inherits="BeforeWebForms2.ControlSamples.GridView.AutoGeneratedColumns" %>
2+
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
3+
4+
<h2>GridView control</h2>
5+
6+
<div>
7+
<a href="Default.aspx">Default</a> | <a href="AutoGeneratedColumns.aspx">AutoGeneratedColumns</a>
8+
</div>
9+
10+
<p>This is just a simple example of a GridView with autogenerated columns</p>
11+
12+
<asp:gridview id="CustomersGridView"
13+
emptydatatext="No data available."
14+
selectMethod="GetCustomers"
15+
ItemType="BeforeWebForms2.ControlSamples.GridView.Customer"
16+
runat="server" DataKeyNames="CustomerID">
17+
</asp:gridview>
18+
19+
</asp:Content>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web;
5+
using System.Web.UI;
6+
using System.Web.UI.WebControls;
7+
8+
namespace BeforeWebForms2.ControlSamples.GridView
9+
{
10+
public partial class AutoGeneratedColumns : System.Web.UI.Page
11+
{
12+
protected void Page_Load(object sender, EventArgs e)
13+
{
14+
15+
}
16+
17+
public List<Customer> GetCustomers()
18+
{
19+
var customers = new List<Customer>();
20+
var c1 = new Customer
21+
{
22+
CustomerID = 1,
23+
FirstName = "John",
24+
LastName = "Smith",
25+
CompanyName = "Virus"
26+
};
27+
28+
var c2 = new Customer
29+
{
30+
CustomerID = 2,
31+
FirstName = "Jose",
32+
LastName = "Rodriguez",
33+
CompanyName = "Boring"
34+
};
35+
36+
37+
var c3 = new Customer
38+
{
39+
CustomerID = 3,
40+
FirstName = "Jason",
41+
LastName = "Ramirez",
42+
CompanyName = "Fun Machines"
43+
};
44+
45+
customers.Add(c1);
46+
customers.Add(c2);
47+
customers.Add(c3);
48+
49+
return customers;
50+
}
51+
}
52+
}

samples/BeforeWebForms2/ControlSamples/GridView/AutoGeneratedColumns.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/BeforeWebForms2/ControlSamples/GridView/Default.aspx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
<h2>GridView control homepage</h2>
55

6+
<div>
7+
<a href="Default.aspx">Default</a> | <a href="AutoGeneratedColumns.aspx">AutoGeneratedColumns</a>
8+
</div>
9+
610
<p>This is just a simple example of a GridView with a selectMethod</p>
711

812
<asp:gridview id="CustomersGridView"

src/BlazorWebFormsComponents/GridView/GridView.razor.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace BlazorWebFormsComponents.GridView
77
{
88
public partial class GridView<ItemType> : BaseModelBindingComponent<ItemType>
99
{
10-
[Parameter] public bool AutogenerateColumns { get; set; }
10+
[Parameter] public bool AutogenerateColumns { get; set; } = true;
1111

1212
[Parameter] public string EmptyDataText { get; set; }
1313

@@ -21,12 +21,13 @@ public partial class GridView<ItemType> : BaseModelBindingComponent<ItemType>
2121

2222
[Parameter] public RenderFragment ChildContent { get; set; }
2323

24-
[CascadingParameter(Name = "Host")] public BaseWebFormsComponent HostComponent { get; set; }
25-
2624
protected override void OnInitialized()
2725
{
28-
HostComponent = this;
2926
base.OnInitialized();
27+
if (AutogenerateColumns)
28+
{
29+
GridViewColumnGenerator.AutogenerateColumns(this);
30+
}
3031
}
3132

3233

0 commit comments

Comments
 (0)