我的方法是这样写的
private void CategoryAllMethod()
{
string departName = this.dplDepartList.SelectedItem.Text;
Department depart = DepartmentManager.GetDepartIdByDepartName(departName);
int departId = depart.DepartId;
//Category cate = categoryManager.GetCategoryByDepartId(departId);
IList<Category> list=categoryManager.GetCategoryListByDepartId(departId);
this.dplCategoryList.DataSource = list;
if (list.Count == 0)
{
// this.dplCategoryList.Item.Clear();
this.dplCategoryList.SelectedItem.Text = "no categories";
}
else
{
this.dplCategoryList.DataValueField = "categoryId";
this.dplCategoryList.DataTextField = "categoryName";
this.dplCategoryList.DataBind(); }
}protected void dplDepartList_SelectedIndexChanged(object sender, EventArgs e)
{
CategoryAllMethod();
}根据第一个dropdownlist值的改变 而改变category的值
如果第一个dropdownlist值里面没有对应的category,我就让category的dropdownlist显示为no categories但是现在的问题是 我通过上述方法 category的dropdownlist的值第一个的确显示的是“no categories”。
但是下面还有初次绑定的时候的那些值。说明category的dropdownlist没有清空。
然后我用this.dplCategoryList.Item.Clear()方法清空,就是我上面注释的那行代码,
运行到this.dplCategoryList.Item.Clear()下一行的时候 就会报 未将对象引用到设置的实例
无论我把那行代码放到if里面 还是外面 都会报这个错请各位帮忙解决一下。谢谢你们了。
private void CategoryAllMethod()
{
string departName = this.dplDepartList.SelectedItem.Text;
Department depart = DepartmentManager.GetDepartIdByDepartName(departName);
int departId = depart.DepartId;
//Category cate = categoryManager.GetCategoryByDepartId(departId);
IList<Category> list=categoryManager.GetCategoryListByDepartId(departId);
this.dplCategoryList.DataSource = list;
if (list.Count == 0)
{
// this.dplCategoryList.Item.Clear();
this.dplCategoryList.SelectedItem.Text = "no categories";
}
else
{
this.dplCategoryList.DataValueField = "categoryId";
this.dplCategoryList.DataTextField = "categoryName";
this.dplCategoryList.DataBind(); }
}protected void dplDepartList_SelectedIndexChanged(object sender, EventArgs e)
{
CategoryAllMethod();
}根据第一个dropdownlist值的改变 而改变category的值
如果第一个dropdownlist值里面没有对应的category,我就让category的dropdownlist显示为no categories但是现在的问题是 我通过上述方法 category的dropdownlist的值第一个的确显示的是“no categories”。
但是下面还有初次绑定的时候的那些值。说明category的dropdownlist没有清空。
然后我用this.dplCategoryList.Item.Clear()方法清空,就是我上面注释的那行代码,
运行到this.dplCategoryList.Item.Clear()下一行的时候 就会报 未将对象引用到设置的实例
无论我把那行代码放到if里面 还是外面 都会报这个错请各位帮忙解决一下。谢谢你们了。
解决方案 »
- 怎么给内部短信加上语音提醒功能啊??
- 急~~水晶报表使用推模式,SetDataSource后还是无数据
- 大家谁知道这是怎么做出来的(高分等待)..给个思路.
- 用c#怎么模拟客户端模拟post提交要求提交的IP是客户端的
- 急 如何设置session过期时间
- 我想禁掉页面中嵌套的一个iframe的右键,该怎么做啊???
- 请教各位,如果想做到点击按钮后,弹出新窗口但不用javscript的window.open或hyperlink,有其它办法吗
- ADO.NET Entity Framework 求教(极度困惑)
- 请问一个SqlDataReader的问题
- 在填写表单的时候怎么用enter代替tab键?
- 求可以直接采集到sql server数据库的网站采集器
- (运行build.bat文件后找不到Microsoft.Web.UI.WebControls.dll文件,)
在用this.dplCategoryList.SelectedItem.Text肯定报错了
运行到this.dplCategoryList.Item.Clear()下一行的时候 就会报 未将对象引用到设置的实例
无论我把那行代码放到if里面 还是外面 都会报这个错
这句改成:
this.dplCategoryList.Items.Add( "no categories");
this.dplCategoryList..SelectedValue= "no categories";
是不要上面我注释的那行代码? 我试过了。这样写的话。之前加载时候的category也会显示在no category 下面
{
this.dplCategoryList.Item.Clear();
this.dplCategoryList.Item.add(new ListItem("no categories","0"));
}
{
this.dplCategoryList.Items.Clear();
ListItem item = new ListItem();
item.Value = "-1";
item.Text = "no categories";
dplCategoryList.Items.Add(item);
}
else
{
this.dplCategoryList.DataValueField = "categoryId";
this.dplCategoryList.DataTextField = "categoryName";
this.dplCategoryList.DataBind(); }
this.dplCategoryList.Items.Add("No categories");我是这样写的 出来了 问题解决了 谢谢你们每一个人!