我正在 Azure 中维护 Azure 移动服务数据。我需要将该 Azure 移动服务数据访问到网页中。
所以,我在 Asp.net(C#) 中创建了一些网页。如何将 Azure 移动服务数据获取到 Asp.net 中的 GridView 中?
但是,我将数据放入普通的 html 表中..按照我的代码进行操作
WebForm1.aspx
<form id="form1" runat="server" >
<table id="DBDataPlaceHolder1" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th class="auto-style1">Code</th>
<th class="auto-style1">Name</th>
<th class="auto-style1">Descrption</th>
<th class="auto-style1">Sort</th>
<th class="auto-style1">Enable</th>
<th class="auto-style1">Action</th>
</tr>
</thead>
<asp:PlaceHolder id="PlaceHolder1" runat="server"></asp:PlaceHolder>
</table>
</form>
WebForm1.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
RetrieveAzureAsync(sender,e);
}
async private void RetrieveAzureAsync(object sender, EventArgs e)
{
IMobileServiceTable<BranchList> BranchTable = client.GetTable<BranchList>();
StringBuilder htmlTable = new StringBuilder();
// This query filters out completed TodoItems and
// items without a timestamp.
List<BranchList> items_list = await BranchTable
.Where(branchitem => branchitem.Enable == true)
.ToListAsync();
int size = items_list.Count();
if (size > 0)
{
for (int i = 0; i < size; i++)
{
htmlTable.Append("<tr>");
htmlTable.Append("<td>" + items_list[i].BranchCode + "</td>");
htmlTable.Append("<td>" + items_list[i].BranchName + "</td>");
htmlTable.Append("<td>" + items_list[i].Descr + "</td>");
htmlTable.Append("<td>" + items_list[i].Sort + "</td>");
htmlTable.Append("<td>" + items_list[i].Enable + "</td>");
htmlTable.Append("<td> <i class='icon-large icon-edit'> <a href='' OnClick='Button1_Click' runat='server' class='icon-large icon-trash'></td>");
htmlTable.Append("</tr>");
}
htmlTable.Append("</table>");
PlaceHolder1.Controls.Add(new Literal { Text = htmlTable.ToString() });
}
}
输出:
如何将 Azure 移动服务数据导入到 Asp.net 中的 GridView 中?请任何人帮助我
最佳答案
最后我找到了将 Azure 移动服务数据导入 GridView 的方法。
List<BranchList> items_list = await BranchTable
.Where(branchitem => branchitem.Enable == true)
.ToListAsync();
MyGridView1.DataSource = items_list;
MyGridView1.DataBind();
关于c# - 如何将Azure Mobile服务数据放入Asp.net(C#)中的 GridView 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31694260/