|
1 | 1 | # Blazor.WebForm.Components |
2 | 2 | ASP.NET Web Forms System.Web.UI.WebControls Razor Components For Blazor WebAssembly. |
| 3 | + |
| 4 | + |
| 5 | +<pre style="background-color: #eeeeee; border: 1px solid rgb(221, 221, 221); box-sizing: border-box; color: #333333; font-family: "Source Code Pro", Consolas, Courier, monospace; font-size: 15px; line-height: 22px; margin-bottom: 22px; margin-top: 22px; max-width: 100%; overflow: auto; padding: 4.5px 11px;"><code class="language-cs hljs" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-radius: 0px; border: none; display: block; font-family: "Source Code Pro", Consolas, Courier, monospace; font-size: 1em; line-height: inherit; margin: 0px; overflow-x: auto; padding: 0px; text-size-adjust: none;">@using System.Web.UI; |
| 6 | +@using System.Web.UI.WebControls; |
| 7 | +@page "/fetchdata-gridview" |
| 8 | +@inherits ControlComponent |
| 9 | +@inject HttpClient Http |
| 10 | + |
| 11 | +<div> |
| 12 | + <h1>Weather forecast (GridView)</h1> |
| 13 | + <asp.Button Text="Load Data" OnClick="this.Button_Click"></asp.Button> |
| 14 | + <hr /> |
| 15 | + <asp.Label @ref="this.label"></asp.Label> |
| 16 | + <br /> |
| 17 | + <asp.GridView @ref="this.gridview" AutoGenerateColumns="false" CssClass="table" AllowPaging="true" |
| 18 | + PageSize="2" OnPageIndexChanging="this.GridView_PageIndexChanging"> |
| 19 | + <Columns> |
| 20 | + <asp.BoundField HeaderText="Date" DataField="Date" DataFormatString="{0:yyyy/M/d}"></asp.BoundField> |
| 21 | + <asp.BoundField HeaderText="Temp. (C)" DataField="TemperatureC"></asp.BoundField> |
| 22 | + <asp.BoundField HeaderText="Temp. (F)" DataField="TemperatureF"></asp.BoundField> |
| 23 | + <asp.BoundField HeaderText="Summary" DataField="Summary"></asp.BoundField> |
| 24 | + </Columns> |
| 25 | + </asp.GridView> |
| 26 | +</div> |
| 27 | + |
| 28 | +@code { |
| 29 | + private WeatherForecast[] forecasts; |
| 30 | + private Label label; |
| 31 | + private GridView gridview; |
| 32 | + |
| 33 | + protected async void Button_Click(object sender, EventArgs e) |
| 34 | + { |
| 35 | + forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json"); |
| 36 | + |
| 37 | + label.Text = DateTime.Now.ToString(); |
| 38 | + |
| 39 | + gridview.PageIndex = 0; |
| 40 | + gridview.DataSource = forecasts; |
| 41 | + gridview.DataBind(); |
| 42 | + |
| 43 | + this.RequestRefresh(); |
| 44 | + } |
| 45 | + |
| 46 | + protected void GridView_PageIndexChanging(object sender, GridViewPageEventArgs e) |
| 47 | + { |
| 48 | + gridview.PageIndex = e.NewPageIndex; |
| 49 | + gridview.DataBind(); |
| 50 | + } |
| 51 | + |
| 52 | + public class WeatherForecast |
| 53 | + { |
| 54 | + public DateTime Date { get; set; } |
| 55 | + |
| 56 | + public int TemperatureC { get; set; } |
| 57 | + |
| 58 | + public string Summary { get; set; } |
| 59 | + |
| 60 | + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); |
| 61 | + } |
| 62 | +}</code></pre> |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | +<a href="https://www.nuget.org/packages/Blazor.WebForm.Components/">https://www.nuget.org/packages/Blazor.WebForm.Components/</a> |
0 commit comments