using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;public partial class mana_mana_directory_houtai_edit : System.Web.UI.Page
{
private string myconnectionstring = ConfigurationManager.ConnectionStrings["conDSN"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Session["user_name"] == null)
{
Response.Redirect("./login.aspx");
}
SetBind();
}
}
protected void rpt_class_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "AddClass")
{
RepeaterItem ri = e.Item;
TextBox tb = ri.FindControl("tb_NewClassName") as TextBox;
string cmd_select_query = "select * from web_directory where directory_name=@url_name";
using (OleDbConnection my_conn = new OleDbConnection(myconnectionstring))
{
my_conn.Open();
using (OleDbCommand my_cmd = new OleDbCommand(cmd_select_query, my_conn))
{
my_cmd.Parameters.AddWithValue("@url_name", tb.Text);
using (OleDbDataReader dr = my_cmd.ExecuteReader())
{
if (dr.Read())
{
Response.Write(@"<script language=javascript>alert('该名称已经存在!');</script>");
}
else
{
//directory_class 0前台,1后台
string cmd_insert_str = "insert into web_directory(directory_parent_id,directory_name,directory_class,directory_status) values(0,@directory_name,1,0)";
using (OleDbConnection my_conn1 = new OleDbConnection(myconnectionstring))
{
my_conn1.Open();
using (OleDbCommand my_cmd_insert = new OleDbCommand(cmd_insert_str, my_conn1))
{
my_cmd_insert.Parameters.AddWithValue("@directory_name", tb.Text);
my_cmd_insert.ExecuteNonQuery();
SetBind();
}
}
}
}
} }
}
if (e.CommandName == "DelClass")
{
//directory_status 0显示 1不显示
string cmd_del = "update web_directory set directory_status='1' where directory_id=@directory_id";
using (OleDbConnection my_conn = new OleDbConnection(myconnectionstring))
{
my_conn.Open();
using (OleDbCommand my_cmd = new OleDbCommand(cmd_del,my_conn))
{
my_cmd.Parameters.AddWithValue("@directory_id",e.CommandArgument);
my_cmd.ExecuteNonQuery();
SetBind();
}
}
}
if (e.CommandName == "ModifyClass")
{
string cmd_update = "update web_directory set directory_name=@directory_name where directory_id=@directory_id";
RepeaterItem ri = e.Item;
TextBox tb=ri.FindControl("btn_Classname") as TextBox;
using (OleDbConnection my_conn = new OleDbConnection(myconnectionstring))
{
my_conn.Open();
using (OleDbCommand my_cmd = new OleDbCommand(cmd_update, my_conn))
{
my_cmd.Parameters.AddWithValue("@directory_name",tb.Text);
my_cmd.Parameters.AddWithValue("@directory_id", e.CommandArgument);
my_cmd.ExecuteNonQuery();
SetBind();
}
}
}
}
private void SetBind()
{
//directory_class 0前台,1后台
string sel_parent = "select * from web_directory where directory_parent_id=0 and directory_class='1' and directory_status='0'";
string sel_child = "select * from web_directory where directory_parent_id<>0 and directory_class='1' and directory_status='0'";
DataSet ds = new DataSet();
using (OleDbConnection my_conn = new OleDbConnection(myconnectionstring))
{
OleDbDataAdapter da = new OleDbDataAdapter(sel_parent, my_conn);
OleDbDataAdapter da1 = new OleDbDataAdapter(sel_child,my_conn);
da.Fill(ds,"parent");
da1.Fill(ds, "child");
}
DataColumn parent_id = ds.Tables["parent"].Columns["directory_id"];
DataColumn child_id = ds.Tables["child"].Columns["directory_parent_id"];
ds.Relations.Add("ParentClassAndBoardClass",parent_id, child_id,false);
this.rpt_class.DataSource = ds.Tables["parent"];
this.rpt_class.DataBind();
}
//public check_filed(string table_name, string table_filed, string sel_field)
//{
// string sel_field_query = "select " + table_filed + " from " + table_name + " where " + table_filed + "=" + sel_field + "";
// using (OleDbConnection my_conn = new OleDbConnection(myconnectionstring))
// {
// my_conn.Open();
// using (OleDbCommand my_cmd = new OleDbCommand(sel_field_query, my_conn))
// {
// using (OleDbDataReader dr = my_cmd.ExecuteReader())
// {
// if (dr.Read())
// {
// return false;
// }
// else
// {
// return true;
// }
// }
// }
// }
//}
}我明明在每个空间操作后都进行了数据重新绑定的调用,也在页面加载的时候进行过了判断。可为什么每次操作后页面空间都不自动绑定呢?
还有就是我想写一个自定义函数用来判断每次操作的字段值是否重复了,函数这一块应该是调用哪个类型的函数呀?
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;public partial class mana_mana_directory_houtai_edit : System.Web.UI.Page
{
private string myconnectionstring = ConfigurationManager.ConnectionStrings["conDSN"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Session["user_name"] == null)
{
Response.Redirect("./login.aspx");
}
SetBind();
}
}
protected void rpt_class_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "AddClass")
{
RepeaterItem ri = e.Item;
TextBox tb = ri.FindControl("tb_NewClassName") as TextBox;
string cmd_select_query = "select * from web_directory where directory_name=@url_name";
using (OleDbConnection my_conn = new OleDbConnection(myconnectionstring))
{
my_conn.Open();
using (OleDbCommand my_cmd = new OleDbCommand(cmd_select_query, my_conn))
{
my_cmd.Parameters.AddWithValue("@url_name", tb.Text);
using (OleDbDataReader dr = my_cmd.ExecuteReader())
{
if (dr.Read())
{
Response.Write(@"<script language=javascript>alert('该名称已经存在!');</script>");
}
else
{
//directory_class 0前台,1后台
string cmd_insert_str = "insert into web_directory(directory_parent_id,directory_name,directory_class,directory_status) values(0,@directory_name,1,0)";
using (OleDbConnection my_conn1 = new OleDbConnection(myconnectionstring))
{
my_conn1.Open();
using (OleDbCommand my_cmd_insert = new OleDbCommand(cmd_insert_str, my_conn1))
{
my_cmd_insert.Parameters.AddWithValue("@directory_name", tb.Text);
my_cmd_insert.ExecuteNonQuery();
SetBind();
}
}
}
}
} }
}
if (e.CommandName == "DelClass")
{
//directory_status 0显示 1不显示
string cmd_del = "update web_directory set directory_status='1' where directory_id=@directory_id";
using (OleDbConnection my_conn = new OleDbConnection(myconnectionstring))
{
my_conn.Open();
using (OleDbCommand my_cmd = new OleDbCommand(cmd_del,my_conn))
{
my_cmd.Parameters.AddWithValue("@directory_id",e.CommandArgument);
my_cmd.ExecuteNonQuery();
SetBind();
}
}
}
if (e.CommandName == "ModifyClass")
{
string cmd_update = "update web_directory set directory_name=@directory_name where directory_id=@directory_id";
RepeaterItem ri = e.Item;
TextBox tb=ri.FindControl("btn_Classname") as TextBox;
using (OleDbConnection my_conn = new OleDbConnection(myconnectionstring))
{
my_conn.Open();
using (OleDbCommand my_cmd = new OleDbCommand(cmd_update, my_conn))
{
my_cmd.Parameters.AddWithValue("@directory_name",tb.Text);
my_cmd.Parameters.AddWithValue("@directory_id", e.CommandArgument);
my_cmd.ExecuteNonQuery();
SetBind();
}
}
}
}
private void SetBind()
{
//directory_class 0前台,1后台
string sel_parent = "select * from web_directory where directory_parent_id=0 and directory_class='1' and directory_status='0'";
string sel_child = "select * from web_directory where directory_parent_id<>0 and directory_class='1' and directory_status='0'";
DataSet ds = new DataSet();
using (OleDbConnection my_conn = new OleDbConnection(myconnectionstring))
{
OleDbDataAdapter da = new OleDbDataAdapter(sel_parent, my_conn);
OleDbDataAdapter da1 = new OleDbDataAdapter(sel_child,my_conn);
da.Fill(ds,"parent");
da1.Fill(ds, "child");
}
DataColumn parent_id = ds.Tables["parent"].Columns["directory_id"];
DataColumn child_id = ds.Tables["child"].Columns["directory_parent_id"];
ds.Relations.Add("ParentClassAndBoardClass",parent_id, child_id,false);
this.rpt_class.DataSource = ds.Tables["parent"];
this.rpt_class.DataBind();
}
//public check_filed(string table_name, string table_filed, string sel_field)
//{
// string sel_field_query = "select " + table_filed + " from " + table_name + " where " + table_filed + "=" + sel_field + "";
// using (OleDbConnection my_conn = new OleDbConnection(myconnectionstring))
// {
// my_conn.Open();
// using (OleDbCommand my_cmd = new OleDbCommand(sel_field_query, my_conn))
// {
// using (OleDbDataReader dr = my_cmd.ExecuteReader())
// {
// if (dr.Read())
// {
// return false;
// }
// else
// {
// return true;
// }
// }
// }
// }
//}
}我明明在每个空间操作后都进行了数据重新绑定的调用,也在页面加载的时候进行过了判断。可为什么每次操作后页面空间都不自动绑定呢?
还有就是我想写一个自定义函数用来判断每次操作的字段值是否重复了,函数这一块应该是调用哪个类型的函数呀?
解决方案 »
- 网页关闭后,弹出添加到收藏夹的代码
- 【Linq】查询包含对不同数据上下文上所定义项的引用??
- 如何截取本页的流,访问a.aspx的同时在服务器上生成一个静态a.htm?
- ASP.net中使用Oracleclient的问题,大虾求救
- 求在GridView中实现链接打开子窗口编辑的功能!
- 水晶报表加入子报表后提示:server has not yet been opened
- 如何显示当前站点所有访问者的IP?
- 高手 求教
- 支付宝API 求获取授权令牌的代码 .NET
- ※※※※※※※※多个dataset显示格式的问题※※※※※※※※
- sandy945 javascript:alert(1.0) 如何输出数字1.0呢,而不是1
- visualstdio里新建的页面不支持样式
if (e.CommandName == "AddClass")
{}//操作结束
BindData();
你的意思是把BindData();
写到所有操作的后面,不放在if语句里呀