File tree Expand file tree Collapse file tree 13 files changed +198
-5
lines changed
AfterBlazorServerSide/Pages/ControlSamples/GridView
src/BlazorWebFormsComponents Expand file tree Collapse file tree 13 files changed +198
-5
lines changed Original file line number Diff line number Diff line change 22 Other usage samples:
33 <NavLink href =" ./ControlSamples/GridView" class =" component-link" Match =" NavLinkMatch.All" >Simple GridView </NavLink > |
44 <NavLink href =" ./ControlSamples/GridView/AutoGeneratedColumns" class =" component-link" Match =" NavLinkMatch.All" >AutoGenerated Columns</NavLink > |
5+ <NavLink href =" ./ControlSamples/GridView/TemplateFields" class =" component-link" Match =" NavLinkMatch.All" >Template Fields</NavLink > |
56</div >
Original file line number Diff line number Diff line change 1+ @page " /ControlSamples/GridView/TemplateFields"
2+
3+ <h2 >GridView Control</h2 >
4+
5+ <Nav ></Nav >
6+
7+ <GridView @ref =" TemplateFieldGridView"
8+ AutogenerateColumns =" false"
9+ ItemType =" SharedSampleObjects.Models.Widget" >
10+ <Columns >
11+ <TemplateField HeaderText =" Name" ItemType =" SharedSampleObjects.Models.Widget" >
12+ <ItemTemplate Context =" Item" >
13+ <Label ID =" lblName" Text =" @Item.Name" ></Label >
14+ </ItemTemplate >
15+ </TemplateField >
16+ <TemplateField HeaderText =" Price" ItemType =" SharedSampleObjects.Models.Widget" >
17+ <ItemTemplate Context =" Item" >
18+ <Label ID =" lblPrice" Text =" @Item.Price" ></Label >
19+ </ItemTemplate >
20+ </TemplateField >
21+ </Columns >
22+ </GridView >
23+
24+ <Button Text =" Click Me!" OnClick =" @Unnamed_Click" />
25+
26+ @code {
27+
28+ BlazorWebFormsComponents .GridView .GridView <Widget > TemplateFieldGridView { get ; set ; }
29+
30+ private static bool PriceVisibility { get ; set ; } = false ;
31+
32+ protected override void OnAfterRender (bool firstRender )
33+ {
34+
35+ if (firstRender )
36+ {
37+ TemplateFieldGridView .DataSource = Widget .Widgets (8 );
38+ TemplateFieldGridView .DataBind ();
39+ }
40+
41+ base .OnAfterRender (firstRender );
42+
43+ }
44+
45+ protected void Unnamed_Click ()
46+ {
47+ // foreach(GridViewRow row in TemplateFieldGridView.Rows)
48+ // {
49+ // var label = row.FindControl("lblPrice") as Label;
50+ // label.Visible = !PriceVisibility;
51+ // }
52+ // PriceVisibility = !PriceVisibility;
53+ }
54+ }
Original file line number Diff line number Diff line change 7171 <Content Include =" ControlSamples\DataList\StyleAttributes.aspx" />
7272 <Content Include =" ControlSamples\GridView\AutoGeneratedColumns.aspx" />
7373 <Content Include =" ControlSamples\GridView\Default.aspx" />
74+ <Content Include =" ControlSamples\GridView\TemplateFields.aspx" />
7475 <Content Include =" ControlSamples\ListView\Default.aspx" />
7576 <Content Include =" ControlSamples\ListView\Grouping.aspx" />
7677 <Content Include =" ControlSamples\ListView\ModelBinding.aspx" />
167168 <Compile Include =" ControlSamples\GridView\Default.aspx.designer.cs" >
168169 <DependentUpon >Default.aspx</DependentUpon >
169170 </Compile >
171+ <Compile Include =" ControlSamples\GridView\TemplateFields.aspx.cs" >
172+ <DependentUpon >TemplateFields.aspx</DependentUpon >
173+ <SubType >ASPXCodeBehind</SubType >
174+ </Compile >
175+ <Compile Include =" ControlSamples\GridView\TemplateFields.aspx.designer.cs" >
176+ <DependentUpon >TemplateFields.aspx</DependentUpon >
177+ </Compile >
170178 <Compile Include =" ControlSamples\ListView\Default.aspx.cs" >
171179 <DependentUpon >Default.aspx</DependentUpon >
172180 <SubType >ASPXCodeBehind</SubType >
Original file line number Diff line number Diff line change 44 <h2 >GridView control</h2 >
55
66 <div >
7- <a href =" Default.aspx" >Default</a > | <a href =" AutoGeneratedColumns.aspx" >AutoGeneratedColumns</a >
7+ <a href =" Default.aspx" >Default</a > | <a href =" AutoGeneratedColumns.aspx" >AutoGeneratedColumns </a > | < a href = " TemplateFields.aspx " >Template Fields</ a >
88 </div >
99
1010 <p >This is just a simple example of a GridView with autogenerated columns</p >
Original file line number Diff line number Diff line change 44 <h2 >GridView control homepage</h2 >
55
66 <div >
7- <a href =" Default.aspx" >Default</a > | <a href =" AutoGeneratedColumns.aspx" >AutoGeneratedColumns</a >
7+ <a href =" Default.aspx" >Default</a > | <a href =" AutoGeneratedColumns.aspx" >AutoGeneratedColumns </a > | < a href = " TemplateFields.aspx " >Template Fields</ a >
88 </div >
99
1010 <p >This is just a simple example of a GridView with a selectMethod</p >
Original file line number Diff line number Diff line change 1+ <% @ Page Title= " " Language= " C#" MasterPageFile= " ~/Site.Master" AutoEventWireup= " true" CodeBehind= " TemplateFields.aspx.cs" Inherits= " BeforeWebForms2.ControlSamples.GridView.TemplateFields" %>
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 > | <a href =" TemplateFields.aspx" >Template Fields</a >
8+ </div >
9+
10+ <p >This is just a simple example of a GridView that uses template fields</p >
11+
12+ <asp:gridview id =" TemplateFieldGridView"
13+ autogeneratecolumns =" False"
14+ ItemType =" SharedSampleObjects.Models.Widget"
15+ runat =" server" >
16+ <Columns >
17+ <asp:TemplateField HeaderText =" Name" >
18+ <ItemTemplate >
19+ <asp:Label ID =" lblName" runat =" server" Text =" <%#:Item.Name %>" ></asp:Label >
20+ </ItemTemplate >
21+ </asp:TemplateField >
22+ <asp:TemplateField HeaderText =" Price" >
23+ <ItemTemplate >
24+ <asp:Label runat =" server" id =" lblPrice" Text =" <%#:Item.Price %>" ></asp:Label >
25+ </ItemTemplate >
26+ </asp:TemplateField >
27+ </Columns >
28+ </asp:gridview >
29+
30+ <asp:Button runat =" server" Text =" Click Me" OnClick =" Unnamed_Click" />
31+ </asp:Content >
Original file line number Diff line number Diff line change 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 BeforeWebForms2 . ControlSamples . GridView
10+ {
11+ public partial class TemplateFields : System . Web . UI . Page
12+ {
13+
14+ private static bool PriceVisibility { get ; set ; } = false ;
15+ protected void Page_Load ( object sender , EventArgs e )
16+ {
17+ TemplateFieldGridView . DataSource = Widget . SimpleWidgetList ;
18+ TemplateFieldGridView . DataBind ( ) ;
19+ }
20+
21+ protected void Unnamed_Click ( object sender , EventArgs e )
22+ {
23+ foreach ( GridViewRow row in TemplateFieldGridView . Rows )
24+ {
25+ var label = row . FindControl ( "lblPrice" ) as Label ;
26+ label . Visible = ! PriceVisibility ;
27+ }
28+ PriceVisibility = ! PriceVisibility ;
29+ }
30+ }
31+ }
32+
Original file line number Diff line number Diff line change 1+ @inherits BaseWebFormsComponent
2+
3+ <button id =" @ID" @onclick =" @TriggerClick" >@Text </button >
4+
Original file line number Diff line number Diff line change 1+ using Microsoft . AspNetCore . Components ;
2+ using System ;
3+ using System . Threading . Tasks ;
4+
5+ namespace BlazorWebFormsComponents
6+ {
7+ public partial class Button : BaseWebFormsComponent
8+ {
9+ [ Parameter ] public string Text { get ; set ; }
10+
11+ [ Parameter ]
12+ public Action OnClick { get ; set ; }
13+
14+ private async Task TriggerClick ( )
15+ {
16+ OnClick ? . Invoke ( ) ;
17+ }
18+ }
19+ }
You can’t perform that action at this time.
0 commit comments