RowFilter 条件过滤类型数据类型出错,好心人帮帮忙!
我想把多层栏目数据绑定到 Dropdownlist,从网上找了下面的代码,在RowFilter 过滤的时候报错了,
语句:dv.RowFilter = "parentid= "+id.ToString();
错误:无法在 System.String 和 System.Int32 上执行“=”操作。
代码如下,有人能指导一下吗?
栏目ID在两位数的时候,程序是正常的,55555
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = GetData();
BindData(dt, "0 ");
}
private void BindData(DataTable dt, string id)
{
DataView dv = new DataView(dt);
//这里错,改为 "parentid=id "没有报错,缺没有数据绑定Dropdownlist3
dv.RowFilter = "parentid= "+id.ToString();
int m = 0;
foreach (DataRowView drv in dv)
{
m++;
string blank = " ";
if (id != "0 ")
{
for (int i = 0; i < m; i++)
{
blank += "|─ ";
}
}
ListItem li = new ListItem();
li.Text = blank + drv[ "id "].ToString() + drv[ "name "].ToString();
li.Value = drv[ "id "].ToString();
this.Dropdownlist3.Items.Add(li);
BindData(dt, drv[ "id "].ToString());
}
}