我在VS。2005里写的程序
页面有个下拉列表框 里面的值是通过数据库提取的
还有个提交按钮 我就像通过点击提交按钮 显示下拉列表中选择的值
但我提交的时候 总是显示的是第一个显示的值 想提取显示下边别的值 显示不了
捆饶很久了
请高手指点啊
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="dropdown1.aspx.cs" Inherits="dropdown1" %>
<!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">
<div>
<asp:DropDownList ID="xl" runat="server" AutoPostBack="True"></asp:DropDownList>
<asp:ListBox ID="xs" runat="server"></asp:ListBox>
<asp:Button ID="tj" runat="server" Text="添加" OnClick="tj_Click" />
</div>
</form>
</body>
</html>
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.OleDb;
public partial class dropdown1 : System.Web.UI.Page
{
protected readonly string AccessString = ConfigurationSettings.AppSettings["AccessConnectionString"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
// if (!IsPostBack)
// {
GetSourceList();
// }
}
protected void GetSourceList()
{
string AccessConnectionString = AccessString + Server.MapPath("csc.mdb");
string cmdtext = "select * from srtype order by stid";
OleDbConnection myConnection = new OleDbConnection(AccessConnectionString);
OleDbCommand myCommand = new OleDbCommand(cmdtext,myConnection);
myConnection.Open();
OleDbDataReader reader1 = myCommand.ExecuteReader();
//xl.Items.Clear();
while (reader1.Read())
{
xl.Items.Add(new ListItem(reader1["stname"].ToString(), reader1["stid"].ToString()));
}
xl.SelectedIndex = 0;
reader1.Close();
myConnection.Close();
}
protected void tj_Click(object sender, EventArgs e)
{
if (xl.SelectedIndex > -1)
{
Response.Write(xl.SelectedItem.Value.ToString());
}
xl.SelectedIndex = 0;
}
}