| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1019 人关注过本帖
标题:datalist如果有了分页后~如何设置修改删除功能 ~?(有图图)
取消只看楼主 加入收藏
HankStar
Rank: 1
等 级:新手上路
帖 子:230
专家分:0
注 册:2006-10-4
收藏
 问题点数:0 回复次数:4 
datalist如果有了分页后~如何设置修改删除功能 ~?(有图图)
当然~编辑功能是可以加上去~

可以只要一点修改删除什么的 ~分页就会消失……

如何解决 ~

还有 求一删除的 代码

VS2005 C# SQL2000

谢谢 ~~

[此贴子已经被作者于2006-11-16 23:23:24编辑过]

搜索更多相关主题的帖子: 图图 datalist 删除 
2006-11-16 21:40
HankStar
Rank: 1
等 级:新手上路
帖 子:230
专家分:0
注 册:2006-10-4
收藏
得分:0 

这个App_Code里面的cs文件~自定义类库

using System;
using System.Data;
using System.Configuration;
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.SqlClient;


public class db
{
protected string connstring ;
private int pagesize;
public db()
{
connstring = ConfigurationManager.ConnectionStrings["Shoping"].ConnectionString;
pagesize = 4;
}
public DataTable dt(string query)
{
SqlConnection con = new SqlConnection(connstring);
SqlDataAdapter sda = new SqlDataAdapter(query, con);
DataSet ds = new DataSet();
sda.Fill(ds, "name");
return ds.Tables["name"];
}

public PagedDataSource pds()
{
PagedDataSource pds = new PagedDataSource();
pds.DataSource = dt("select * from Customer").DefaultView;
pds.AllowPaging = true;
pds.PageSize = pagesize;
pds.CurrentPageIndex = pds.CurrentPageIndex;
return pds;
}

public PagedDataSource pds(int pg)
{
PagedDataSource pds = new PagedDataSource();
pds.DataSource = dt("select * from Customer").DefaultView;
pds.AllowPaging = true;//允许分页
pds.PageSize = pagesize;//显示多少项
pds.CurrentPageIndex = pg;//当前页的索引
return pds;
}

public int sql(string query)
{
SqlConnection con = new SqlConnection(connstring);
con.Open();
SqlCommand cmd = new SqlCommand(query, con);
return cmd.ExecuteNonQuery();
}
}



这个是分页
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;

public partial class shiyan_shiyan2 : System.Web.UI.Page
{
private static int p;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
int n;
if (Request.QueryString["page"] != null)
{
n = Convert.ToInt32(Request.QueryString["page"]);

}
else
{
n = 0;
}
p = n;
bind(n);
}
}
private void bind(int n)
{
db sdb = new db();
DataList1.DataSource = sdb.pds(n);
DataList1.DataBind();
}
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Footer)
{
if (e.Item.ItemType == ListItemType.Footer)
{
//PlaceHolder ph = new PlaceHolder();
PlaceHolder ph = (PlaceHolder)e.Item.FindControl("ph");
db sdb = new db();
for (int i = 0; i < sdb.pds().PageCount; i++)
{
HyperLink hl = new HyperLink();
Literal nsb = new Literal();


int n = i + 1;
hl.Text = n.ToString();
hl.ID = n.ToString();
hl.NavigateUrl = "?page=" + i.ToString();
nsb.Text = " ";

ph.Controls.Add(hl);
ph.Controls.Add(nsb);
}
}
}
}


}




这个是编辑,删除的~~
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.SqlClient;

public partial class shiyan_shiyan1 : System.Web.UI.Page
{
//public static string con;
//con=ConfigurationManager.ConnectionStrings["Shoping"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}

public void bind()
{
DataList3.DataSource = dt("select top 10 * from Customer");
DataList3.DataKeyField="C_Name";
DataList3.DataBind();
}
public DataTable dt(string qq)
{
string con = ConfigurationManager.ConnectionStrings["Shoping"].ConnectionString;
SqlConnection sc = new SqlConnection(con);
sc.Open();
SqlDataAdapter sda = new SqlDataAdapter(qq, sc);
DataSet ds = new DataSet();

sda.Fill(ds, "name");
return ds.Tables["name"];
}

public int eut(string qq)
{
string con = ConfigurationManager.ConnectionStrings["Shoping"].ConnectionString;
SqlConnection sc = new SqlConnection(con);
sc.Open();

SqlCommand cmd = new SqlCommand(qq,sc);
return cmd.ExecuteNonQuery();
}

protected void DataList3_CancelCommand(object source, DataListCommandEventArgs e)
{
DataList3.EditItemIndex = -1;
bind();
}
protected void DataList3_EditCommand(object source, DataListCommandEventArgs e)
{
DataList3.EditItemIndex = e.Item.ItemIndex;
bind();
}

protected void DataList3_DeleteCommand(object source, DataListCommandEventArgs e)
{

//string id = DataList3.DataKeyField[e.Item.ItemIndex].ToString();
string id = ((Label)e.Item.FindControl("Label4")).Text.Trim();
string qq = "delete from Customer where C_Name='" + id + "'";
if (eut(qq) > 0)
{

DataList3.EditItemIndex = -1;
bind();
}

}

protected void DataList3_UpdateCommand(object source, DataListCommandEventArgs e)
{
//string id = DataList3.DataKeyField[e.Item.ItemIndex].ToString();
string id = ((Label)e.Item.FindControl("Label4")).Text.Trim();
string datetime = ((TextBox)e.Item.FindControl("TextBox1")).Text.Trim();
string emaile = ((TextBox)e.Item.FindControl("TextBox2")).Text.Trim();
string qq = "update Customer set C_DateTime='" + datetime + "',C_Emaile='" + emaile + "' where C_Name='" + id +"'";
if(eut(qq) > 0)
{
DataList3.EditItemIndex = -1;
bind();
}
}
/*
protected void DataList3_ItemCommand(object source, DataListCommandEventArgs e)
{
string id = ((Label)e.Item.FindControl("Label4")).Text.Trim();
string qq = "delete from Customer where C_Name='" + id + "'";
if (eut(qq) > 0)
{

DataList3.EditItemIndex = -1;
bind();
}
}
*/

}


如何把2,3结合在一起~~
当编辑的时候~分页继续出现~

protected void DataList3_DeleteCommand(object source, DataListCommandEventArgs e)
{

//string id = DataList3.DataKeyField[e.Item.ItemIndex].ToString();
string id = ((Label)e.Item.FindControl("Label4")).Text.Trim();
string qq = "delete from Customer where C_Name='" + id + "'";
if (eut(qq) > 0)
{

DataList3.EditItemIndex = -1;
bind();
}

}
这个删除好像删除失败……帮忙改一下~~

图片附件: 游客没有浏览图片的权限,请 登录注册

图片附件: 游客没有浏览图片的权限,请 登录注册

[此贴子已经被作者于2006-11-16 23:14:32编辑过]


2006-11-16 23:10
HankStar
Rank: 1
等 级:新手上路
帖 子:230
专家分:0
注 册:2006-10-4
收藏
得分:0 
代码和图图已经上传……

等待中 ~~


2006-11-16 23:16
HankStar
Rank: 1
等 级:新手上路
帖 子:230
专家分:0
注 册:2006-10-4
收藏
得分:0 

轻轻一顶~~


2006-11-17 11:32
HankStar
Rank: 1
等 级:新手上路
帖 子:230
专家分:0
注 册:2006-10-4
收藏
得分:0 
以下是引用bygg在2006-11-17 21:03:15的发言:
protected void DataList3_DeleteCommand(object source, DataListCommandEventArgs e)
{

//string id = DataList3.DataKeyField[e.Item.ItemIndex].ToString();
string id = ((Label)e.Item.FindControl("Label4")).Text.Trim();
string qq = "delete from Customer where C_Name='" + id + "'";
if (eut(qq) > 0)
{

DataList3.EditItemIndex = -1;
bind();
}

}
这个删除好像删除失败……帮忙改一下~~



你先把你的 qq 这个输出来看看SQL语句有没有错?

没有错~~


2006-11-17 23:01
快速回复:datalist如果有了分页后~如何设置修改删除功能 ~?(有图图)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018380 second(s), 11 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved