【www.gdgbn.com--CMS技巧】

//添加删除确认对话框:
private void DataGrid1_ItemDataBound( )
{
switch(e.Item.ItemType)
{
case ListItemType.Item:
case ListItemType.AlternatingItem:
case ListItemType.EditItem:
ImageButton btn = (ImageButton)e.Item.FindControl("btnDelete");
btn.Attributes.Add("onclick", "return confirm("你是否确定删除这条记录?");");
break;

}
}
处理操作:
private void DataGrid1_ItemCommand()
{
string c=e.CommandName;
int PermissionsID =(int)this.DataGrid1.DataKeys[e.Item.ItemIndex];//DataKeyField值
switch(c)
{
case "Delete":
//执行删除操作
break;

}

}

还有个好方法:
datagrid-》属性生成器-》列-》添加按钮列-》删除-》文本(T)->在文本框里加上:
Script:return confirm("确定删除吗?")">删除
就可以了/
OK!

//重新取值赋值:
private void DataGrid1_ItemDataBound( )
{
if((e.Item.ItemType==ListItemType.Item)||(e.Item.ItemType==ListItemType.AlternatingItem))
{
//e.Item代表一行

string ImgUrl = (string)DataBinder.Eval(e.Item.DataItem, "ImageUrl");
//注意这一行,"ImageUrl"字段是什么类型前面就转成什么类型,否则报错

//e.Item.Cells[0].Style.Add("font-weight", "bold");
//e.Item.Cells[0].ForeColor = System.Drawing.Color.Red; //e.Item.BackColor = System.Drawing.Color.AliceBlue;
string s=e.Item.DataItem.ToString();
string ss=e.Item.Cells[0].Text;
int sss=e.Item.Cells.Count;

}
}


//绑定是重新计算页数与当前页

public void dataShowBind(DataSet ds)
{
this.DataGrid1.DataSource=ds;
if(ds.Tables.Count>0)
{
int rowscount=ds.Tables[0].Rows.Count;

本文来源:http://www.gdgbn.com/wangyezhizuo/8850/