我在repeater里面放了一个表 表里面有2个Label和一个TextBox 两个Button 这些不是重点
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
/*DataRowView dv = (DataRowView)e.Item.DataItem; -----这里我注释掉了,本来我向这里连接,下面的操作都可以用着command 但是 update操作可以 但是 只要delete 操作全都是asp.net未将对象引用设置到对象的实例错误 string floor = dv["floor"].ToString();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text; */
if (e.CommandName == "edit")
{
TextBox bb = (TextBox)e.Item.FindControl("TextBox1");
Button tt = (Button)e.Item.FindControl("Button1"); if (!bb.Enabled)
{
bb.Enabled = true; tt.Text = "发布";
}
else
{
DataRowView dv = (DataRowView)e.Item.DataItem; string floor = dv["floor"].ToString(); OleDbCommand cmd = new OleDbCommand(); cmd.Connection = con; cmd.CommandText = "update tabl1 set [text] ='" + bb.Text + "' where t_id='" + Session["t_id"].ToString() + "'&&floor=" + floor; cmd.ExecuteNonQuery(); bb.Enabled = false; // tt.Text = "编辑"; // con.Close(); }
} if(e.CommandName == "dele")
{ DataRowView dvv = (DataRowView)e.Item.DataItem; string floorr = dvv["floor"].ToString(); //asp.net未将对象引用设置到对象的实例错误在这里发生 OleDbCommand cmd = new OleDbCommand(); cmd.Connection = con; cmd.CommandType = CommandType.Text; con.Open(); cmd.CommandText = "delete from tabl1 where t_id='" + Session["t_id"].ToString() + "' &&floor=" + floorr; cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery();
}
}
执行delete操作就asp.net未将对象引用设置到对象的实例错误 而update操作就可以
我甚至改了commandText 内容外 其他内容都一样也不行 求教
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
/*DataRowView dv = (DataRowView)e.Item.DataItem; -----这里我注释掉了,本来我向这里连接,下面的操作都可以用着command 但是 update操作可以 但是 只要delete 操作全都是asp.net未将对象引用设置到对象的实例错误 string floor = dv["floor"].ToString();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text; */
if (e.CommandName == "edit")
{
TextBox bb = (TextBox)e.Item.FindControl("TextBox1");
Button tt = (Button)e.Item.FindControl("Button1"); if (!bb.Enabled)
{
bb.Enabled = true; tt.Text = "发布";
}
else
{
DataRowView dv = (DataRowView)e.Item.DataItem; string floor = dv["floor"].ToString(); OleDbCommand cmd = new OleDbCommand(); cmd.Connection = con; cmd.CommandText = "update tabl1 set [text] ='" + bb.Text + "' where t_id='" + Session["t_id"].ToString() + "'&&floor=" + floor; cmd.ExecuteNonQuery(); bb.Enabled = false; // tt.Text = "编辑"; // con.Close(); }
} if(e.CommandName == "dele")
{ DataRowView dvv = (DataRowView)e.Item.DataItem; string floorr = dvv["floor"].ToString(); //asp.net未将对象引用设置到对象的实例错误在这里发生 OleDbCommand cmd = new OleDbCommand(); cmd.Connection = con; cmd.CommandType = CommandType.Text; con.Open(); cmd.CommandText = "delete from tabl1 where t_id='" + Session["t_id"].ToString() + "' &&floor=" + floorr; cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery();
}
}
执行delete操作就asp.net未将对象引用设置到对象的实例错误 而update操作就可以
我甚至改了commandText 内容外 其他内容都一样也不行 求教
解决方案 »
- asp.net网站 前台参数由之前的id 变为name 结果只能读到数据表中的第一条记录
- 关于构造器的一点小疑问
- 求sharpmap如何渲染MS SQL Server等格式的GIS数据?
- 牛人们帮忙啊,请问一下在.net如何实现注释的国际化
- 小弟对委托和事件的理解,不知道对不对,请大家指点一下
- 求C#相关您最经典最喜爱的BOOK,不限中外。
- 怎样监视事件被何时调用?
- dotnetfx35 和 winfrom程序如何集成到一起啊?
- 在C#怎么实现文件复制命令?
- C#使用chart控件获得数据库数据绘曲线图
- listView中怎样随输入而添加行,再怎样根据名字搜索某行名字所在行
- 求用1个datagridview同时显示多条结果。
当repeater控件的EnableViewState为true时 Repeater1_ItemCommand处理函数的函数无法执行但是EnableViewState为false时 可以操作repeater控件里的控件状态 redirect这样的操作都可以执行 但是像上面的代码就执行不了 太奇怪了
召唤大能 教教无知的我吧 这把我弄烦死了 这是连续得 第三个回复了 希望大能救我 这个发完了 我就回复不了了求教大能