怎样在DataGrid中通过双击来修改数据,同时保存到数据库中
解决方案 »
- (新手求指教).net中获取客户端ip的问题,在本的的电脑上可以获取,在外网上不可以
- 问一个Linq语句该怎么写
- 多站点同步更新
- viewstate又保存不了数据了
- 怎么做一个sp,统计每条新闻每天,每月,每年的电击数
- 在使用activeX“组合框”控件时必须点击两次按钮才能提交?
- 请问 谁知道 智联招聘 这个公司怎么样呀
- 怎么把DropDownListd类的一个对象返回给DropDownlist服务器控件?
- 请教安装vs.net的顺序
- SqlDataAdapter更新数据出错,我是参照MSDN上做的呀。
- 请教客户端脚本失效的原因?
- pocket pc pda mobilephone 的初级问题。
{
e.Item.Attributes.Add("onmousemove", "if(this.rowIndex>0){this.style.backgroundColor='#e7e7ff';this.style.cursor='hand';}");
e.Item.Attributes.Add("onmouseout", "this.style.color='#000000';if(this.rowIndex%2==0&&this.rowIndex>0){this.style.backgroundColor='#eeeeee';} else if(this.rowIndex>0){this.style.backgroundColor='#ffffff';}");
e.Item.Attributes.Add("onDblClick", "if(this.rowIndex>0)window.open('show.aspx?id="+e.Item.Cells[0].Text.ToString()+"')");
}
private void DataGrid2_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if(e.Item.ItemIndex>-1)
{
LinkButton tmp = e.Item.Cells[1].Controls[0] as LinkButton;
e.Item.Attributes.Add("ondblclick", Page.GetPostBackEventReference(tmp).Replace(":","$"));
}
} private void DataGrid2_ItemCommand(object source, DataGridCommandEventArgs e)
{
this.TextBox1.Text = System.DateTime.Now.ToString();
}
双击时,单元格变为可编辑,在单元格的值改变事件中写保存即可单元格的值改变事件是哪个
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;using System.Web.Mail;
using System.IO;namespace score
{
/// <summary>
/// SendEmail 的摘要说明。
/// </summary>
public class SendEmail : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox tbTo;
protected System.Web.UI.WebControls.TextBox tbFrom;
protected System.Web.UI.WebControls.TextBox tbPwd;
protected System.Web.UI.WebControls.TextBox tbCopyTo;
protected System.Web.UI.WebControls.TextBox tbSubject;
protected System.Web.UI.WebControls.TextBox tbBody;
protected System.Web.UI.WebControls.Button btnSend;
protected System.Web.UI.HtmlControls.HtmlInputFile AttachFile;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnSend.Click += new System.EventHandler(this.btnSend_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void btnSend_Click(object sender, System.EventArgs e)
{
//分别取得邮件的收信人的地址、发信人的地址、抄送、主题、内容等信息
string strTo = tbTo.Text;
string strFrom = tbFrom.Text;
string strPwd = tbPwd.Text;
string strCopyTo = tbCopyTo.Text;
string strSubject = tbSubject.Text;
string strBody = tbBody.Text; try
{
MailMessage ms=new MailMessage(); ms.To = strTo; //收信人的地址
ms.From = strFrom; //发信人的地址
ms.Cc = strCopyTo; //抄送
ms.Subject = strSubject; //主题
ms.Body = strBody; //正文 string strPathOfAttachFile = ""; //初始化附件
//如果有附件则上传
HttpPostedFile hpPFile = AttachFile.PostedFile; //获得上传文件的访问
if(hpPFile.FileName != "")
{
//有附件,则上传到Temp目录中
//判断是否存在Temp目录,若无,则创建
string FolderName = Server.MapPath(".") + "\\Temp";
if(Directory.Exists(FolderName) == false)
Directory.CreateDirectory(FolderName);
//取得文件名(不含路径)
char[] separator = {'\\'}; //separator的值为"\"
string[] AFileName = hpPFile.FileName.Split(separator);
string strFileName = AFileName[AFileName.Length-1];
strPathOfAttachFile = Server.MapPath(".")+"\\Temp\\"+strFileName;
hpPFile.SaveAs(strPathOfAttachFile);
//添加附件
ms.Attachments.Add(new MailAttachment(strPathOfAttachFile)); } //从发信人的地址计算出邮件服务器
string[] strTemp = strFrom.Split('@');
string strPartOfSmtpServer = strTemp[strTemp.Length-1];
string strSmtpServer = "smtp." + strPartOfSmtpServer; ms.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");//value=0 No Check value=1 Basic Check Value=2 Exchage Check
ms.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", strFrom); //发信人的邮箱地址
ms.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", strPwd);//验证信息
SmtpMail.SmtpServer=strSmtpServer; //邮件服务器ip或域名 SmtpMail.Send(ms); //发送
//清除控件中的内容
tbTo.Text = "";
tbCopyTo.Text = "";
tbSubject.Text = "";
tbBody.Text = "";
//删除Temp目录中的附件
if(File.Exists(strPathOfAttachFile) == true)
File.Delete(strPathOfAttachFile);
//确认邮件发送成功
string strScript = "<script>alert('邮件发送成功!')</script>";
if (! Page.IsStartupScriptRegistered("Alert"))
{
Page.RegisterStartupScript("Alert", strScript);
} }
catch
{
string strScript = "<script>alert('邮件发送失败!')</script>";
if (! Page.IsStartupScriptRegistered("Alert"))
{
Page.RegisterStartupScript("Alert", strScript);
} }
}
}
}
http://community.csdn.net/Expert/topic/3399/3399546.xml?temp=.6452295