.net ListView控件中嵌套TextBox控件,TextBox如何赋值?

<ItemTemplate><tdid="Td3"runat="server"><asp:LabelID="characterLabel"runat="server"Te... <ItemTemplate>
<td id="Td3" runat="server">
<asp:Label ID="characterLabel" runat="server" Text='<%# Eval("character") %>' />
<br />
<asp:Label ID="pinyinLabel" runat="server" />
<br />
</td>
</ItemTemplate>
第二个label的值我想从数据库中读出,且让他只在点击某个按钮的时候显示。
展开
 我来答
huangpeng0419
2010-11-16 · TA获得超过357个赞
知道小有建树答主
回答量:569
采纳率:100%
帮助的人:292万
展开全部
分享下自己的学习成果......
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ListViewOne.aspx.cs" Inherits="ListViewOne" %>

<!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>ListView</title>

<script src="Scripts/jquery-1.4.2.min.js" type="text/javascript"></script>

<script type="text/javascript">
$(document).ready(function() {
$(".wa").click(function() {
var tr = $(this.parentNode.parentNode);
var lblID = $("span[id$=lblID]", tr);
var pinyinLabel = $("span[id$=pinyinLabel]", tr);
$.get("ListViewOne.aspx?ajaxRequest=true&val=" + lblID.text() + "&x=" + Math.random(),
function(result) {
pinyinLabel.html(result);
}
);
});
});
</script>

</head>
<body>
<form id="form1" runat="server">
<asp:ListView ID="lvPersons" runat="server">
<LayoutTemplate>
<table border="1" style="border-collapse: collapse" width="100%">
<thead>
<tr>
<td>
ID
</td>
<td>
Name
</td>
<td>
Sex
</td>
<td>
Description
</td>
<td>
Op
</td>
</tr>
</thead>
<tbody>
<asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
</tbody>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="lblID" runat="server" Text='<%#Eval("ID") %>' />
</td>
<td>
<asp:Label ID="lblName" runat="server" Text='<%#Eval("Name")%>' />
</td>
<td>
<asp:Label ID="lblSex" runat="server" Text='<%#Eval("Sex")%>' />
</td>
<td>
<asp:Label ID="pinyinLabel" runat="server" />
</td>
<td>
<input type="button" class="wa" value="Get" />
</td>
</tr>
</ItemTemplate>
<EmptyDataTemplate>
No records found!!!
</EmptyDataTemplate>
</asp:ListView>
</form>
</body>
</html>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ListViewOne : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(Request.QueryString["ajaxRequest"]))
{
Response.Clear();
PersonInfo person = new PersonInfo().GetData().Where(p => p.ID == int.Parse(Request.QueryString["val"])).First();
if (person != null)
Response.Write(person.Description);
else
Response.Write("not found!!!");
Response.End();
}
if (IsPostBack) return;
lvPersons.DataSource = new PersonInfo().GetData();
lvPersons.DataBind();
}
}

class PersonInfo
{
public int ID { get; set; }
public string Name { get; set; }
public string Sex { get; set; }
public string Description { get; set; }

public List<PersonInfo> GetData()
{
return new List<PersonInfo>()
{
new PersonInfo(){ID=1,Name="张三",Sex="男",Description="aa"},
new PersonInfo(){ID=2,Name="李四",Sex="男",Description="bb"},
new PersonInfo(){ID=3,Name="王八",Sex="男",Description="cc"},
new PersonInfo(){ID=4,Name="张三",Sex="男",Description="dd"},
new PersonInfo(){ID=5,Name="李四",Sex="男",Description="ee"},
new PersonInfo(){ID=6,Name="王八",Sex="男",Description="ff"},
new PersonInfo(){ID=7,Name="张三",Sex="男",Description="gg"},
new PersonInfo(){ID=8,Name="李四",Sex="男",Description="yy"},
new PersonInfo(){ID=9,Name="王八",Sex="男",Description="xx"},
new PersonInfo(){ID=10,Name="张三",Sex="男",Description="ss"},
new PersonInfo(){ID=11,Name="李四",Sex="男",Description="rr"},
new PersonInfo(){ID=12,Name="王八",Sex="男",Description="tt"},
new PersonInfo(){ID=13,Name="张三",Sex="男",Description="uu"},
new PersonInfo(){ID=14,Name="李四",Sex="男",Description="ii"},
new PersonInfo(){ID=15,Name="王八",Sex="男",Description="oo"},
new PersonInfo(){ID=16,Name="张三",Sex="男",Description="pp"},
new PersonInfo(){ID=17,Name="李四",Sex="男",Description=";;"},
new PersonInfo(){ID=18,Name="王八",Sex="男",Description="ll"},
new PersonInfo(){ID=19,Name="张三",Sex="男",Description="aa"},
new PersonInfo(){ID=20,Name="李四",Sex="男",Description="aa"},
new PersonInfo(){ID=21,Name="王八",Sex="男",Description="aa"},
new PersonInfo(){ID=22,Name="张三",Sex="男",Description="aa"},
new PersonInfo(){ID=23,Name="李四",Sex="男",Description="aa"},
new PersonInfo(){ID=24,Name="张三",Sex="男",Description="aa"},
new PersonInfo(){ID=25,Name="李四",Sex="男",Description="aa"},
new PersonInfo(){ID=26,Name="翠花",Sex="女",Description="aa....."},
};
}
}

参考资料: http://code.jquery.com/jquery-1.4.2.min.js

新乡宇工环保设备公司
2010-11-16 · TA获得超过235个赞
知道小有建树答主
回答量:379
采纳率:0%
帮助的人:150万
展开全部
protected void Button1_Click(object sender, EventArgs e)
{
//值我想从数据库中读出
strSQL="select 你想要的 from 表where.."
//然后就是连接数据库什么的,得到dateset ds
string 值=ds.Tables[0].rows[0][0].tostring();
label.text=值;
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式