[英]How to send Data from Funcation to Html page list in Web Form
I have a Application I neaver work on Web Form so simple I have to send a data to html page.. 我有一个Neaver在Web窗体上工作的应用程序,所以我必须将数据发送到html页面。
in the First page I have a Button and a listBox 在第一页中,我有一个Button和一个listBox
<asp:Button ID="Button12" runat="server" Text="Button" OnClick="Button12_Click" />
<asp:ListBox ID="ListBox1" runat="server"></asp:ListBox>
So when I click the button it should send list of user to the list box 因此,当我单击按钮时,它应该将用户列表发送到列表框中
protected void Button12_Click(object sender, EventArgs e)
{
ApplicationDbContext obk = new ApplicationDbContext();
foreach (var item in obk.Users.ToList())
{
ListBox1.Text = item.UserName;
}
First it is not showing the data in the list box 首先,它不在列表框中显示数据
second I want to send a data from C# to Html like in MVC we have ViewData["jsad"] so is there any thing in Web Form I am new in Web Forms I work on MVC so I am so confuse 第二,我想将数据从C#发送到HTML,就像在MVC中一样,我们有ViewData [“ jsad”],所以Web窗体中有什么东西吗?我在MVC上工作的Web窗体中是新手,所以我很困惑
And you can give me any good web link for tutorial for Web form , 您可以给我任何有关Web表单教程的良好Web链接,
First you have to add ListItem
to show item.UserName
in your ListBox
. 首先,您必须添加
ListItem
以在ListBox
显示item.UserName
。
protected void Button12_Click(object sender, EventArgs e)
{
ApplicationDbContext obk = new ApplicationDbContext();
foreach (var item in obk.Users.ToList())
{
ListBox1.Items.Add(item.UserName);
}
}
Secondly, I think Page.Items
is very equivalent to ViewData
. 其次,我认为
Page.Items
非常等同于ViewData
。 It's IDictionary
so you can add and show the value of "jsad" like this. 这是
IDictionary
因此您可以像这样添加和显示“ jsad”的值。
aspx.cs: aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
Page.Items["jsad"] = "value";
// or Page.Items.Add("jsad", "value");
}
aspx: aspx:
<div>jsad = <%: Page.Items["jsad"] %></div>
and here is a good reference for MVC developers to understand WebForms. 这是MVC开发人员了解WebForms的很好参考。 http://www.codeproject.com/Articles/528117/WebForms-vs-MVC
http://www.codeproject.com/Articles/528117/WebForms-vs-MVC
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.