我用下拉菜单选择相关内容,然后提交去SQL库里搜索,然后显示出来,,,
例如:SQL有列 ID,,NAME,,TEXT我用DropDownList去选择ID,然后跟当页的@NAME一起去库里搜索想对应的数据要怎么写啊?DropDownList用的数据绑定。我找了些代码该了可是有问题。。ASPX文件: <tr>
<td style="width: 100px">
发放时间</td>
<td style="width: 100px">
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource3"
DataTextField="time" DataValueField="time" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList><asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:gz %>"
SelectCommand="SELECT [time] FROM [gzmx] where (gh=@gh) ">
<SelectParameters>
<asp:SessionParameter Name="gh" SessionField="gh" Type="String" /> <%--接收登陆信息中的用户名--%>
</SelectParameters>
</asp:SqlDataSource>
</td>
<td style="width: 100px">
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /></td>
</tr>
</table>
<br />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 Default2 : System.Web.UI.Page
{ protected System.Web.UI.WebControls.DropDownList DirectionList1;
protected void Page_Load(object sender, EventArgs e)
{
if (this.Session["gh"] == null)
{
Response.Redirect("Login.aspx");
} //如果没有登陆信息中的用户名信息则返回登陆页面
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{ }
protected void DataList1_SelectedIndexChanged(object sender, EventArgs e)
{ }
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["gzdb"]); //创建连接对象
SqlCommand cmd = new SqlCommand("select * from gzmx where time='" + this.DropDownList1.SelectedValue + "'", conn); //创建查询用户名是否存在数据对象
Session["time"] = this.DropDownList1.SelectedValue;//存储用户名
}
}
他提示错误:
编译错误
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 编译器错误信息: CS0117: “Default2”并不包含“DropDownList1”的定义源错误: 行 42: {
行 43: SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["gzdb"]); //创建连接对象
行 44: SqlCommand cmd = new SqlCommand("select * from gzmx where time='" + this.DropDownList1.SelectedValue + "'", conn); //创建查询用户名是否存在数据对象
行 45: Session["time"] = this.DropDownList1.SelectedValue;//存储用户名
行 46:
源文件: d:\WebSite1\Default2.aspx.cs 行: 44 奇怪的是我用STUDIO2005的调试去测试网站可以显示出数据,而且数据都对,但在STUDIO2005的错误报告还显示控件没有定义,但是直接输入地址就不行我改怎么写?求高手给出源文件。
例如:SQL有列 ID,,NAME,,TEXT我用DropDownList去选择ID,然后跟当页的@NAME一起去库里搜索想对应的数据要怎么写啊?DropDownList用的数据绑定。我找了些代码该了可是有问题。。ASPX文件: <tr>
<td style="width: 100px">
发放时间</td>
<td style="width: 100px">
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource3"
DataTextField="time" DataValueField="time" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList><asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:gz %>"
SelectCommand="SELECT [time] FROM [gzmx] where (gh=@gh) ">
<SelectParameters>
<asp:SessionParameter Name="gh" SessionField="gh" Type="String" /> <%--接收登陆信息中的用户名--%>
</SelectParameters>
</asp:SqlDataSource>
</td>
<td style="width: 100px">
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /></td>
</tr>
</table>
<br />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 Default2 : System.Web.UI.Page
{ protected System.Web.UI.WebControls.DropDownList DirectionList1;
protected void Page_Load(object sender, EventArgs e)
{
if (this.Session["gh"] == null)
{
Response.Redirect("Login.aspx");
} //如果没有登陆信息中的用户名信息则返回登陆页面
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{ }
protected void DataList1_SelectedIndexChanged(object sender, EventArgs e)
{ }
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["gzdb"]); //创建连接对象
SqlCommand cmd = new SqlCommand("select * from gzmx where time='" + this.DropDownList1.SelectedValue + "'", conn); //创建查询用户名是否存在数据对象
Session["time"] = this.DropDownList1.SelectedValue;//存储用户名
}
}
他提示错误:
编译错误
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 编译器错误信息: CS0117: “Default2”并不包含“DropDownList1”的定义源错误: 行 42: {
行 43: SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["gzdb"]); //创建连接对象
行 44: SqlCommand cmd = new SqlCommand("select * from gzmx where time='" + this.DropDownList1.SelectedValue + "'", conn); //创建查询用户名是否存在数据对象
行 45: Session["time"] = this.DropDownList1.SelectedValue;//存储用户名
行 46:
源文件: d:\WebSite1\Default2.aspx.cs 行: 44 奇怪的是我用STUDIO2005的调试去测试网站可以显示出数据,而且数据都对,但在STUDIO2005的错误报告还显示控件没有定义,但是直接输入地址就不行我改怎么写?求高手给出源文件。
<head id="Head1" runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div style="text-align: center">
<strong><span style="font-size: 24pt"> 工 资 单
</span></strong>
<br />
<br />
<asp:DataList ID="DataList1" runat="server" DataKeyField="gh"
DataSourceID="SqlDataSource2" OnSelectedIndexChanged="DataList1_SelectedIndexChanged">
<ItemTemplate>
<div style="text-align: center">
<table border="1">
<tr>
<td style="width: 100px; height: 23px">
<strong>工 号:</strong></td>
<td style="width: 100px; height: 23px">
<asp:Label ID="gh" runat="server" Text='<%# Eval("gh") %>'></asp:Label></td>
<td style="width: 100px; height: 23px">
<strong>姓 名:</strong></td>
<td style="width: 100px; height: 23px">
<asp:Label ID="xm" runat="server" Text='<%# Eval("xm") %>'></asp:Label></td>
<td style="width: 100px; height: 23px">
<strong>部 门:</strong></td>
<td style="width: 100px; height: 23px">
<asp:Label ID="bm" runat="server" Text='<%# Eval("bm") %>'></asp:Label></td>
</tr>
</table>
</div>
</ItemTemplate>
</asp:DataList><asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:gz %>"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT [gh], [xm], [bm] FROM [Users] where (gh=@gh)">
<SelectParameters>
<asp:SessionParameter Name="gh" SessionField="gh" Type="String" /> <%--接收登陆信息中的用户名--%>
</SelectParameters>
</asp:SqlDataSource>
<table>
<tr>
<td style="width: 100px">
发放时间</td>
<td style="width: 100px">
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource3"
DataTextField="time" DataValueField="time">
</asp:DropDownList><asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:gz %>"
SelectCommand="SELECT [time] FROM [gzmx] where (gh=@gh) ">
<SelectParameters>
<asp:SessionParameter Name="gh" SessionField="gh" Type="String" /> <%--接收登陆信息中的用户名--%>
</SelectParameters>
</asp:SqlDataSource>
</td>
<td style="width: 100px">
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /></td>
</tr>
</table>
<br />
<asp:DataList ID="DataList2" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<table border="1" style="width: 640px; height: 141px">
<tr>
<td style="width: 170px; height: 25%">
<strong>发 放 日 期</strong></td>
<td style="width: 130px; height: 25%">
<asp:Label ID="time" runat="server" Text='<%# Eval("time") %>'></asp:Label></td>
<td style="width: 170px; height: 25%">
<strong>实 发 金 额</strong></td>
<td style="width: 130px; height: 25%">
<asp:Label ID="sfje" runat="server" Text='<%# Eval("sfje") %>'></asp:Label></td>
</tr>
<tr>
<td style="width: 170px; height: 25%">
<strong>基 本 工 资</strong></td>
<td style="width: 130px; height: 25%">
<asp:Label ID="jbgz" runat="server" Text='<%# Eval("jbgz") %>'></asp:Label></td>
<td style="width: 170px; height: 25%">
<strong>职 能 加 给</strong></td>
<td style="width: 130px; height: 25%">
<asp:Label ID="znjg" runat="server" Text='<%# Eval("znjg") %>'></asp:Label></td>
</tr>
<tr>
<td style="width: 170px; height: 25%">
<strong>全 勤 奖</strong></td>
<td style="width: 130px; height: 25%">
<asp:Label ID="qqj" runat="server" Text='<%# Eval("qqj") %>'></asp:Label></td>
<td style="width: 170px; height: 25%">
<strong>工 资 总 额</strong></td>
<td style="width: 130px; height: 25%">
<asp:Label ID="gzze" runat="server" Text='<%# Eval("gzze") %>'></asp:Label></td>
</tr>
<tr>
<td style="width: 170px; height: 25%">
<strong>业务考核奖金</strong></td>
<td style="width: 130px; height: 25%">
<asp:Label ID="ywkh" runat="server" Text='<%# Eval("ywkh") %>'></asp:Label></td>
<td style="width: 170px; height: 25%">
<strong>餐 费 津 贴</strong></td>
<td style="width: 130px; height: 25%">
<asp:Label ID="cfjt" runat="server" Text='<%# Eval("cfjt") %>'></asp:Label></td>
</tr>
<tr>
<td style="width: 170px; height: 25%">
<strong>劳动报酬总额</strong></td>
<td style="width: 130px; height: 25%">
<asp:Label ID="ldbcze" runat="server" Text='<%# Eval("ldbcze") %>'></asp:Label></td>
<td style="width: 170px; height: 25%">
</td>
<td style="width: 130px; height: 25%">
</td>
</tr>
</table>
<br />
</ItemTemplate>
</asp:DataList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=WJ;Initial Catalog=gz;Persist Security Info=True;User ID=sa;Password=wjy"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT [time], [jbgz], [znjg], [qqj], [gzze], [ywkh], [cfjt], [ldbcze], [jrjbf], [jbf], [bsy], [kqt], [qjcd], [wgk], [kgjj], [ksy], [kyl], [yfje], [yl], [dyje], [sl], [sds], [sfje] FROM [gzmx] where (gh=@gh)and (time=@time) ">
<SelectParameters>
<asp:SessionParameter Name="gh" SessionField="gh" Type="String" />
<asp:SessionParameter Name="time" SessionField="time" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
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 Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (this.Session["gh"] == null)
{
Response.Redirect("Login.aspx");
} //如果没有登陆信息中的用户名信息则返回登陆页面
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void DataList1_SelectedIndexChanged(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["gzdb"]); //创建连接对象
SqlCommand cmd = new SqlCommand("select * from gzmx where time='" + this.DropDownList1.SelectedValue + "'", conn); //创建查询用户名是否存在数据对象
Session["time"] = this.DropDownList1.SelectedValue;//存储用户名
}
}