获取了DataList的记录主键值,其它字段值均好找:
http://www.cnblogs.com/insus/archive/2013/01/20/2868403.html
http://www.cnblogs.com/insus/archive/2013/01/20/2868403.html
解决方案 »
- 做的一个自定义控件出现问题
- 如何把动态生成的控件做成预定义控件?
- 哪里有vs2005安装文件?
- ASP.NET系统,业务修改如何实现在线更新?
- 用.net开发一个rss在线阅读的网站大概要多少米?
- 为何我的asp.net页面上的所有控件的事件在编译后总是自动清除掉
- 不是很明白单元测试的作用,你们认为单元测试很有用吗?
- 如何在dropdownlist中显示符合要求的值???
- 怎么回事啊,我在浏览器中键入这样的地址http://127.0.0.1/guestbook/default.aspx,系统怎么会弹出下载对话框,而浏览其它网站的.aspx网页
- Framework Beta2 安装后ASP就不能解析了吗??昨天我装完后就再也解析不了了,请问怎么解决这个问题
- 怎么使用javascript获取控件的ID
- asp.net添加用ckeditor保存后如何正确显示在网页上
<asp:DataList ID="DataList1" runat="server" RepeatColumns="1">
<ItemTemplate>
<tr>
<td>
<table id="Table2" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>
<%# DataBinder.Eval(Container.DataItem, "字段1")%>
</td>
</tr>
</table>
</td>
</tr>
</ItemTemplate>
</asp:DataList>
请问如何获取DataList中的某一个值?
如果前者,铵钮是放在DataList行内,还是放在DataList外?
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;namespace IM
{
public partial class WebForm17 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List<string> list = new List<string>();
list.Add("test");
list.Add("test1");
list.Add("test2");
list.Add("test3"); DataList1.DataSource = list.Select(x => new { 字段1 = x });
DataList1.DataBind();
}
} protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < DataList1.Items.Count; i++)
{
Response.Write(DataList1.DataKeys[i].ToString());
}
}
}
}<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm17.aspx.cs" Inherits="IM.WebForm17" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="DataList1" runat="server" DataKeyField="字段1" RepeatColumns="1">
<ItemTemplate>
<tr>
<td>
<table id="Table2" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>
<%# DataBinder.Eval(Container.DataItem, "字段1")%>
</td>
</tr>
</table>
</td>
</tr>
</ItemTemplate>
</asp:DataList>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</div>
</form>
</body>
</html>