.net ListView控件中嵌套TextBox控件,TextBox如何赋值?
发布网友
发布时间:2024-10-02 06:24
我来回答
共2个回答
热心网友
时间:2024-10-29 19:03
分享下自己的学习成果......
<%@ 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
热心网友
时间:2024-10-29 19:03
protected void Button1_Click(object sender, EventArgs e)
{
//值我想从数据库中读出
strSQL="select 你想要的 from 表where.."
//然后就是连接数据库什么的,得到dateset ds
string 值=ds.Tables[0].rows[0][0].tostring();
label.text=值;
}