我的代码:aspx文件<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %><!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">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true">
</asp:ScriptManager>
<table>
<tr>
<td style="width: 100px">
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional"> <ContentTemplate>
<asp:DropDownList ID="ddlMine" runat="server" Width="150px" AutoPostBack="True" OnSelectedIndexChanged="ddlMine_SelectedIndexChanged">
</asp:DropDownList>
<asp:TextBox ID="tbMine" runat="server" Width="284px"><asp:TextBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlMine" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
</table>
</form>
</body>
</html>aspx.cs文件:using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page
{
protected SqlCommon conn = new SqlCommon();//数据库类 protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
try
{
string strSql = string.Empty;
strSql = "select MineName from Mine where AreaNum='01'"; conn.open();
DataSet myDsDP = conn.ExceDS(strSql);//此方法返回一个DataSet类型
for (int i = 0; i < myDsDP.Tables[0].Rows.Count; i++)
{
ddlMine.Items.Add(myDsDP.Tables[0].Rows[i][0].ToString());
}
}
catch
{
Response.Write("<script language=javascript>alert('读取数据库失败!!!')</script>");
}
finally
{
conn.close();
}
}
} protected void ddlMine_SelectedIndexChanged(object sender, EventArgs e)
{
tbMine.Text = ddlMine.SelectedItem.Text;
}出现错误弹出一个Microsoft Internet Explorer页面对话框:
回发或回调参数无效。在配置中使用<page enableEventValidation="true"/>或在页面中使用<%@ Page enableEventValidation="true" %>启用了事件验证。出于安全目的,此功能验证回发或回调事件的参数是否来源于最初呈现这些事件的服务器控件。如果数据有效并且是预期的,则使用ClientScriptManager.ReristerForEventValidation方法来注册回发或回调数据以进行验证。
在线等,解决马上给分!!!!
Namespace="System.Web.UI" TagPrefix="asp" %><!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">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true">
</asp:ScriptManager>
<table>
<tr>
<td style="width: 100px">
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional"> <ContentTemplate>
<asp:DropDownList ID="ddlMine" runat="server" Width="150px" AutoPostBack="True" OnSelectedIndexChanged="ddlMine_SelectedIndexChanged">
</asp:DropDownList>
<asp:TextBox ID="tbMine" runat="server" Width="284px"><asp:TextBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlMine" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
</table>
</form>
</body>
</html>aspx.cs文件:using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page
{
protected SqlCommon conn = new SqlCommon();//数据库类 protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
try
{
string strSql = string.Empty;
strSql = "select MineName from Mine where AreaNum='01'"; conn.open();
DataSet myDsDP = conn.ExceDS(strSql);//此方法返回一个DataSet类型
for (int i = 0; i < myDsDP.Tables[0].Rows.Count; i++)
{
ddlMine.Items.Add(myDsDP.Tables[0].Rows[i][0].ToString());
}
}
catch
{
Response.Write("<script language=javascript>alert('读取数据库失败!!!')</script>");
}
finally
{
conn.close();
}
}
} protected void ddlMine_SelectedIndexChanged(object sender, EventArgs e)
{
tbMine.Text = ddlMine.SelectedItem.Text;
}出现错误弹出一个Microsoft Internet Explorer页面对话框:
回发或回调参数无效。在配置中使用<page enableEventValidation="true"/>或在页面中使用<%@ Page enableEventValidation="true" %>启用了事件验证。出于安全目的,此功能验证回发或回调事件的参数是否来源于最初呈现这些事件的服务器控件。如果数据有效并且是预期的,则使用ClientScriptManager.ReristerForEventValidation方法来注册回发或回调数据以进行验证。
在线等,解决马上给分!!!!
<%@ Page enableEventValidation="false"%>
位置放对了吗
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div style="float: left">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" Width="98px" AutoPostBack="true"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" OnTextChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="true" Width="168px"
OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList3" runat="server" AutoPostBack="true" Width="168px">
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
</div>
Dropdownlist选来选取都显示的是第一个选项呀?
Dropdownlist选来选去Dropdownlist都显示的是第一个选项呀,tbMine得到的也是第一项呀?
里面的呀!
Namespace="System.Web.UI" TagPrefix="asp" %><!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">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<table>
<tr>
<td style="width: 100px">
<asp:UpdatePanel ID="UpdatePanel2" runat="server"> <ContentTemplate>
<asp:DropDownList ID="ddlMine" runat="server" Width="150px" AutoPostBack="True" OnSelectedIndexChanged="ddlMine_SelectedIndexChanged">
</asp:DropDownList>
<asp:TextBox ID="tbMine" runat="server" Width="284px"><asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
</table>
</form>
</body>
</html>另外,你的SelectedIndexChanged事件只是实现在文本框显示下拉框的值这个功能吗?那用UpdatePanel有点小题大做了
用UpdatePanel有点小题大做了,那么这么小的题我都实现不了,学习嘛
试试用js来实现吧:<!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">
function ddlChange(ddl)
{
document.getElementById("<%= tbMine.ClientID %>").value = ddl.options[ddl.selectedIndex].value;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<table>
<tr>
<td style="width: 100px">
<asp:DropDownList ID="ddlMine" runat="server" Width="150px" onchange="ddlChange(this);">
</asp:DropDownList>
<asp:TextBox ID="tbMine" runat="server" Width="284px"><asp:TextBox>
</td>
</tr>
</table>
</form>
</body>
</html>