关于dropdownlist中value的用法 54行出错,DropDownList1没有选中的ITEM,请检查DropDownList1中是否有数据 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 SqlDataAdapter myComm=new SqlDataAdapter("select id,image_name from image_lou where louid="+louid,myConn); DataSet ds=new DataSet(); myComm.Fill(ds,"louming"); this.DropDownList1.DataSource=ds.Tables["louming"].DefaultView; this.DropDownList1.DataTextField="image_name"; this.DropDownList1.DataValueField="id"; this.DropDownList1.DataBind(); myConn.Close();上面这段代码写在if(!Page.IsPostBack){ //codehere}中 DropDownList1绑定数据后,默认是不选中任何一项的,所以strSql+=this.DropDownList1.SelectedItem.Value;会得到“未将对象引用设置到对象的实例”错误。你可以在绑定后,给DropDownList1选择一个缺省选项,如第0项:DropDownList1.SelectedIndex=0; 我发现数据库搜索结果为空,请教高手,用在dropdownlist中用什么方法或属性获得这个空值呢? ListItem litem=DropDownList1.SelectedItem;if(litem!=null)strSql+=litem.Value; if(this.DropDownList1.SelectedIndex>=0){ strSql+=this.DropDownList1.SelectedItem.Value;}else{ strSql+="-1";//数据库中永远没有ID=-1,也就是找不到数据} 求救vista ultimate下如何安装vs 2008? Session的问题 服务器上无法显示asp.net页面 求开发一个小系统步骤..... 大哥大姐帮帮忙吧!有分哦!小妹先谢了.. 动态导航栏实现问题 DataList中如何显示存储于数据表的图片。 gridview 模板列事件 菜鸟请教一个关于.NET中连接数据库的问题,在线等,请高手指教! 如何获取数据库的用户表名?如何获取某张表的所有字段名?v 弹出窗口的问题,在线等待 c#是否有这样的功能?刚变四个裤衩,特放200分表示一下!:)
DataSet ds=new DataSet();
myComm.Fill(ds,"louming");
this.DropDownList1.DataSource=ds.Tables["louming"].DefaultView;
this.DropDownList1.DataTextField="image_name";
this.DropDownList1.DataValueField="id";
this.DropDownList1.DataBind();
myConn.Close();
上面这段代码写在
if(!Page.IsPostBack)
{
//codehere
}
中
会得到“未将对象引用设置到对象的实例”错误。
你可以在绑定后,给DropDownList1选择一个缺省选项,如第0项:
DropDownList1.SelectedIndex=0;
请教高手,用在dropdownlist中用什么方法或属性获得这个空值呢?
if(litem!=null)
strSql+=litem.Value;
{
strSql+=this.DropDownList1.SelectedItem.Value;
}
else
{
strSql+="-1";//数据库中永远没有ID=-1,也就是找不到数据
}