[求助]DropDownList 控件绑定.
<%@ Page Language="C#" Debug="True" %><%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb"%>
<script runat="server">
private void Page_Load(Object sender,EventArgs E)
{
if(!IsPostBack)
{
DataZLei();
}
}
//-----------------------------------------
public void DataZLei()
{
OleDbConnection cnn;
OleDbCommand cmd;
OleDbDataReader datar;
string strcnn,sql;
strcnn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("../../EDNdata/EDNdatabase.mdb");
cnn=new OleDbConnection(strcnn);
cnn.Open();
sql="select * from ZLei";
cmd=new OleDbCommand(sql,cnn);
datar=cmd.ExecuteReader();
while(datar.Read())
{
ListItem theitem=new ListItem();
theitem=ListItem(datar["Title"].ToString());
theitem.Value=datar["ZClass"].ToString();
drop1.Item.add(theitem);
}
cnn.Close();
}
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<form runat="server">
<table width="760" height="150" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="185" align="right">类别:</td>
<td width="575"><asp:DropDownList id="drop1" runat="server" BackColor="#000000" BorderColor="#330000" class="gcc" >
</asp:DropDownList></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</form>
</body>
</html>
string不能隐式转换为Object......
ListItem theitem=new ListItem();
theitem=ListItem(datar["Title"].ToString());
theitem.Value=datar["ZClass"].ToString();
drop1.Item.add(theitem);
错误在这里..
我不知道怎么改 大家帮帮我..我折腾了一天了