请看代码:
private void BindListBox()
{
string DBDriver = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
Server.MapPath( "DataBase\\Product_List.xls" ) + ";"
+ "Extended Properties=Excel 8.0;";
string SQLString = "Select * from [Sheet1$]"; ArrayList ServiceTag = new ArrayList();
ServiceTag.Add( " " ); try
{
OleDbConnection ExcelConnect = new OleDbConnection( DBDriver );
OleDbCommand ExcelCommand = new OleDbCommand( SQLString, ExcelConnect );
OleDbDataReader ExcelReader;
ExcelConnect.Open();
ExcelReader = ExcelCommand.ExecuteReader(); while( ExcelReader.Read())
{
ServiceTag.Add( ExcelReader[0].ToString() );
}
//ServiceTag_List.DataTextField = "ColorTextField";
//ServiceTag_List.DataValueField = "ColorValueField"; ServiceTag_List.DataSource = ServiceTag;
ServiceTag_List.DataBind(); ExcelConnect.Close();
}
catch( OleDbException j )
{
Message.Show( "DataBase connect failed,Please contact Admin !" );
}
}为何我用ServiceTag_List.SelectItem.Text却得到不选项值了,请指点!
private void BindListBox()
{
string DBDriver = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
Server.MapPath( "DataBase\\Product_List.xls" ) + ";"
+ "Extended Properties=Excel 8.0;";
string SQLString = "Select * from [Sheet1$]"; ArrayList ServiceTag = new ArrayList();
ServiceTag.Add( " " ); try
{
OleDbConnection ExcelConnect = new OleDbConnection( DBDriver );
OleDbCommand ExcelCommand = new OleDbCommand( SQLString, ExcelConnect );
OleDbDataReader ExcelReader;
ExcelConnect.Open();
ExcelReader = ExcelCommand.ExecuteReader(); while( ExcelReader.Read())
{
ServiceTag.Add( ExcelReader[0].ToString() );
}
//ServiceTag_List.DataTextField = "ColorTextField";
//ServiceTag_List.DataValueField = "ColorValueField"; ServiceTag_List.DataSource = ServiceTag;
ServiceTag_List.DataBind(); ExcelConnect.Close();
}
catch( OleDbException j )
{
Message.Show( "DataBase connect failed,Please contact Admin !" );
}
}为何我用ServiceTag_List.SelectItem.Text却得到不选项值了,请指点!
解决方案 »
- 讨论ASP.NET中大家都是如何控制刷新的
- 可不可以定义接口来实现
- 寻找“口口加一”
- 三层结构使用事务
- DataList无法显示!
- 请问如何在ASP.NET网页中连接已编译好的JAR包
- DataGrid显示数据的问题,什么原因为什么显示不了数据?
- 如何去掉HyperLink1里的空格?HyperLink1.NavigateUrl.Replace(" ","")=="";会报搓
- 关于在DataGrid中删除一行数据时。主键为两个字段,该怎么解决。
- 难题,如何在CodeBehind的事件处理中获得Javascript中__doPostBack('ControlsUniqueID',event)中的event参数
- 有谁知道vss怎么配置,客户端怎么访问?
- 昨天没有解决的问题,麻烦大家帮我看看,急啊55555。。。
确定有数据存在?
//ServiceTag_List.DataValueField = "ColorValueField";用ArrayList不太好,用DataTable试试
SqlConnection conn=new SqlConnection(connstr);
conn.Open();
string sqldropdown="select plcname from police order by plcname";
SqlDataAdapter da=new SqlDataAdapter(sqldropdown,conn);
DataSet dr=new DataSet();
da.Fill(dr,"VIEW_USRACT");
DataView dv=dr.Tables[0].DefaultView;
this.ComboBox1.Items.Clear();
for(int i=0;i<dv.Count;i++)
{
this.ComboBox1.Items.Add(dv[i][0].ToString());
}
试一下 SqlDatareader与ServiceTag_List 邦定。
DDL_Class.Items.Add(new ListItem("请选择...","0"));
SqlStr = "select * from ExamClass";
try
{
SqlDataReader dr = SQLHelper.ExecuteReader(SQLHelper.CONN_STRING,CommandType.Text,SqlStr,null);
while(dr.Read()){
DDL_Class.Items.Add(new ListItem(dr["ClassName"].ToString(),dr["ClassID"].ToString()));
}
dr.Close();
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
是不是你的整个页面或者是Dropdownlist控件所在父控件或者它本身被禁用了viewstate?
在v1.1版本中,就是有这个问题.我试过几次了.
还有其他的一些v1.1版本带的bug,我在网络上搜索也没得到合适的答案,我把他们归为bug
请在页面的初始化事件处理程序中重新绑定Dropdownlist的值,也可以开启viewstate.
原因:你在pageload事件处理程序中或其他后于Page.Init事件处理程序中绑定值!