gpt4 book ai didi

jquery - 来自代码隐藏数据表的 ShieldUI 网格数据

转载 作者:行者123 更新时间:2023-12-01 08:44:01 25 4
gpt4 key购买 nike

我用 ShieldUI 实现了 jQuery gridview。我遇到的问题是网格的数据源。

这是他们的示例: http://demos.shieldui.com/web/grid-general/basic-usage

我需要从在代码隐藏中创建的数据表发送数据。

是否可以将此类数据发送到 ShieldDataSource?

谢谢。

<%@ Page Title="" Language="C#" MasterPageFile="Site.Master" AutoEventWireup="true" CodeBehind="Progress2.aspx.cs" Inherits="INAWebAppTest.Form.Progress2" %>

<%@ Register Assembly="Shield.Web.UI" Namespace="Shield.Web.UI" TagPrefix="shield" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent2" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="server">
<script type="text/javascript" src="//www.shieldui.com/shared/components/latest/js/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="//www.shieldui.com/shared/components/latest/js/shieldui-all.min.js"></script>


<section class="success" id="about">
<div class="container">


<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>

<asp:Label ID="Label1" runat="server"><h3>Progress</h3></asp:Label>
<div class="g-hr type_short type_simple">
<span class="g-hr-h">
<i class="fa fa-"></i>
</span>
</div>
<div style="vertical-align: top; margin-bottom: 0px; align-content: center; margin-left: auto; margin-right: auto">
<asp:Button ID="LeftButton" runat="server" Text="<" class="g-btn type_primary size_small" OnClick="ibDLeft_Click" />
<asp:TextBox ID="tbDate" runat="server" AutoPostBack="True" OnTextChanged="tbDate_TextChanged" ReadOnly="true" Style="width: 30%; text-align: center" TextMode="SingleLine"></asp:TextBox>
<asp:Button ID="RightButton" runat="server" Text=">" class="g-btn type_primary size_small" OnClick="ibDRight_Click" />

</div>
<asp:RequiredFieldValidator ID="RequiredFieldValidator" runat="server" ControlToValidate="tbDate" ErrorMessage="Odaberite datum" />

<shield:ShieldDataSource ID="shieldDataSource" runat="server" Data="testData"> </shield:ShieldDataSource>
<shield:ShieldGrid ID="ShieldGrid1" runat="server" ClientDataSourceID="shieldDataSource">
<Columns>
<shield:GridColumn Field="dfCategory" Width="70px" Title="ID"></shield:GridColumn>
<shield:GridColumn Field="dfActivityID" Title="Person Name"></shield:GridColumn>
<shield:GridColumn Field="dfActivityName" Title="Company Name"></shield:GridColumn>
</Columns>
</shield:ShieldGrid>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</section>
</asp:Content>

最佳答案

您可以在页面加载方法中执行以下操作,只需将 DataSource 的 Data 属性设置为 aspx 中的 testData 即可工作。

<shield:ShieldDataSource ID="shieldDataSource" runat="server" Data="testData"> 
</shield:ShieldDataSource>
<shield:ShieldGrid ID="grid" runat="server" ClientDataSourceID="shieldDataSource">
<Sorting Enabled="true" />
<Columns>
<shield:GridColumn Field="Id" />
<shield:GridColumn Field="Name" />
<shield:GridColumn Field="Category" />
<shield:GridColumn Field="Date" />
<shield:GridColumn Field="Available" />
</Columns>
</shield:ShieldGrid>


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
var dt = new DataTable();
dt.Columns.Add(new DataColumn("Id", typeof(int)));
dt.Columns.Add(new DataColumn("Name", typeof(string)));
dt.Columns.Add(new DataColumn("Category", typeof(int)));
dt.Columns.Add(new DataColumn("Date", typeof(DateTime)));
dt.Columns.Add(new DataColumn("Available", typeof(bool)));

var row = dt.NewRow();
row["Id"] = 1;
row["Name"] = "test";
row["Category"] = 2;
row["Date"] = DateTime.Now;
row["Available"] = true;
dt.Rows.Add(row);

var source = (from r in dt.AsEnumerable()
select new
{
Id = r["Id"],
Name = r["Name"],
Category = r["Category"],
Date = r["Date"],
Available = r["Available"],
}).ToList();
var script = "window.testData = " + Shield.Mvc.UI.Common.Serialization.JavaScriptSerializer.Serialize(source);
ClientScript.RegisterClientScriptBlock(this.GetType(), "TableData", script, true);
}
}

关于jquery - 来自代码隐藏数据表的 ShieldUI 网格数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44184938/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com