Repeater 每一行循环出一个文本框,和下拉框 只要下拉框值变,文本框就赋上下拉框的值 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 看好了是repeater 里面的文本框和下拉框 只要你会英文.其实就是按你说的写:循环(){new 文本框,new 下拉框 }if(下拉框值变){文本框.值=下拉框.值} //下拉框事件 protected void DDLZhiwei_SelectedIndexChanged(object sender, EventArgs e) { DropDownList d = sender as DropDownList; TextBox TextBox1 = d.Parent.FindControl("Tbzhiwei") as TextBox; TextBox1.Text = d.SelectedItem.Text; bind1(); }很简单的事情,3行代码就能改变 现在的ajax编程非常诡异,许多号称“高级”的人如果你看其产品,其实也就是最低级的编程能力。 用js比较好。不要用服务端控件。JS参数要传入下拦控件和文本框控件的ID页面<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %><!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> <script type="text/javascript" language="javascript"> function a(drp1) { var lastpos=drp1.id.lastIndexOf('_'); if(lastpos>0) { var txtid= drp1.id.substring(0,lastpos)+"_TextBox1"; document.getElementById(txtid).value=drp1.value; } } </script></head><body> <form id="form1" runat="server"> <div> <asp:Repeater ID="Repeater1" runat="server" onitemdatabound="Repeater1_ItemDataBound"> <ItemTemplate> <%#Eval("col") %> <asp:DropDownList ID="DropDownList1" runat="server" onchange="a(this)"> </asp:DropDownList> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </ItemTemplate> </asp:Repeater> </div> </form></body></html>代码using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;namespace WebApplication1{ public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { DataTable dt = new DataTable(); dt.Columns.Add("col"); DataRow dw = dt.NewRow(); dw[0] = "a"; dt.Rows.Add(dw); dw = dt.NewRow(); dw[0] = "b"; dt.Rows.Add(dw); Repeater1.DataSource = dt; Repeater1.DataBind(); } } protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) { DropDownList d1 = (DropDownList)e.Item.FindControl("DropDownList1"); d1.Items.Add("a"); d1.Items.Add("b"); } }} 楼上完美的回答,不过有点小瑕疵,我补上 function a(drp1) { var lastpos=drp1.id.lastIndexOf('_'); if(lastpos>0) { var txtid= drp1.id.substring(0,lastpos)+"_TextBox1"; document.getElementById(txtid).value=drp1.options[drp1.options.selectedIndex].innerHTML; } }这样子才能获得下拉框选中的值 JQuery的问题 用户登录验证 模拟请求页面,返回的cookie 为空,为什么! loading 效果。昨天搞了一天,请教大家了可还是不行.. 如何写一个对话框实现163邮箱的登陆? c#调用c++的结构体和函数 我用c#两个星期!想请各位高手介绍我一本关于WINDOWSSERVICE的书(电子版的)!急!来者有分 现在上codeproject网站怎么这么慢啊?已经很久了!关于字体变形的问题! 请高手帮我看看 请问有没有C#编写asp.net的例子? 是学 winform 好还是 WPF 好? WPF TreeViewItem Style设置的问题
循环()
{new 文本框,new 下拉框 }
if(下拉框值变)
{文本框.值=下拉框.值}
protected void DDLZhiwei_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList d = sender as DropDownList;
TextBox TextBox1 = d.Parent.FindControl("Tbzhiwei") as TextBox;
TextBox1.Text = d.SelectedItem.Text;
bind1();
}很简单的事情,3行代码就能改变
JS参数要传入下拦控件和文本框控件的ID
页面
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %><!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>
<script type="text/javascript" language="javascript">
function a(drp1)
{
var lastpos=drp1.id.lastIndexOf('_');
if(lastpos>0)
{
var txtid= drp1.id.substring(0,lastpos)+"_TextBox1";
document.getElementById(txtid).value=drp1.value;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server"
onitemdatabound="Repeater1_ItemDataBound">
<ItemTemplate>
<%#Eval("col") %>
<asp:DropDownList ID="DropDownList1" runat="server" onchange="a(this)">
</asp:DropDownList>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
代码
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("col");
DataRow dw = dt.NewRow();
dw[0] = "a";
dt.Rows.Add(dw);
dw = dt.NewRow();
dw[0] = "b";
dt.Rows.Add(dw);
Repeater1.DataSource = dt;
Repeater1.DataBind();
}
} protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
DropDownList d1 = (DropDownList)e.Item.FindControl("DropDownList1");
d1.Items.Add("a");
d1.Items.Add("b");
}
}
}
function a(drp1)
{
var lastpos=drp1.id.lastIndexOf('_');
if(lastpos>0)
{
var txtid= drp1.id.substring(0,lastpos)+"_TextBox1";
document.getElementById(txtid).value=drp1.options[drp1.options.selectedIndex].innerHTML; }
}
这样子才能获得下拉框选中的值