System.data.datable可在大火中使用吗?
我是大麻店的新手,并且正试图使用它。 我尝试重新创建中继器,并试图使用System.Data.DataTable来绑定它,但似乎不可能这样做,而且我也找不到如何调用行的方法。
关于如何在Glazor中使用DataTable的回旋方式吗?
<Repeater2 Items=@dtTest>
<RepeaterContainerTemplate Context=ItemsContent>
<table class="table table-condensed table-bordered">
<thead>
<tr>
<th class="text-center">Text A</th>
<th class="text-center">Text B</th>
<th class="text-center">Text C</th>
</tr>
</thead>
<tbody>
@ItemsContent
</tbody>
</table>
</RepeaterContainerTemplate>
<ItemTemplate Context=test>
<tr>
<td class="text-center">@test["Text_A"]</td>
<td class="text-center">@test["Text_B"]</td>
<td class="text-center">@test["Text_C"]</td>
</tr>
</ItemTemplate>
</Repeater2>
I'm new to blazor and was trying to use it.
I tried recreating the repeater and was trying to bind it using System.Data.DataTable but it seems to be impossible to do it and also i can't find a way on how to call the rows.
Is there a roundabout way on how to use DataTable in Blazor?
<Repeater2 Items=@dtTest>
<RepeaterContainerTemplate Context=ItemsContent>
<table class="table table-condensed table-bordered">
<thead>
<tr>
<th class="text-center">Text A</th>
<th class="text-center">Text B</th>
<th class="text-center">Text C</th>
</tr>
</thead>
<tbody>
@ItemsContent
</tbody>
</table>
</RepeaterContainerTemplate>
<ItemTemplate Context=test>
<tr>
<td class="text-center">@test["Text_A"]</td>
<td class="text-center">@test["Text_B"]</td>
<td class="text-center">@test["Text_C"]</td>
</tr>
</ItemTemplate>
</Repeater2>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这不是在大火中做事的方法。我将Dapper用于我的SQL查询,并且我的数据方法返回键入
list
。这使得Linq可以在标记中的循环中对我的查询进行排序,过滤或以其他方式操纵我的查询结果非常容易。这比在Winforms或WebForms中所做的事情要容易得多,在Winforms或WebForms中,您必须在CodeBehind中使用数据表,行等。您不必创建一个中继器或任何ASP.NET Web表单列表对象,因为现在您可以在标记中使用C#逻辑来决定渲染内容以及如何渲染,并且根据我的经验,这是无限的。
This is not how to do things in Blazor. I use Dapper for my SQL queries, and my data methods return a typed
List
. This makes it very easy with Linq to sort, filter, or otherwise manipulate my query results inforeach
loops in the markup. This is much easier than the way things used to be done in Winforms or Webforms, where you had to work with data tables, rows and so on in codebehind.You don't have to create a repeater or any of the asp.net Web Forms listing objects, because now you can use C# logic in your markup to decide what and how to render, and in my experience this is infinitely better.
您可以使用System.Data.Databable在Glazor应用程序中,
这是您的HTML,
这是您的代码
You can use System.Data.DataTable in Blazor application like this
This is your html
This is your code behind
您可以在互联网上的许多网站上找到与此类似的东西,因此我基本上只是在反思现有的东西。
mytable.razor
,这是使用组件的
fetchdata
的版本。请注意,我将始终使用适当的视图服务进行我的数据管理,因此
WeatherForecast []
将生活在该服务中而不是UI中。You can find something similar to this on many sites on the Internet, so I'm just basically regurgitating what's already out there.
MyTable.razor
And here's a version of
FetchData
that uses the component.Note that I would always use a proper view service for my data management so
WeatherForecast[]
would live in that service and not in the UI.