怎样在DataGrid中通过双击来修改数据,同时保存到数据库中

解决方案 »

  1.   

    DataGrid.Attribute.add("ondblclick","window.open('editpage.aspx')");看这样能不能满足你的要求。
      

  2.   

    private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {

    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()+"')");


    }
      

  3.   

    添加一个按钮列,然后让DataGrid双击触发该按钮列的postback;至于你要在按钮列做什么就是你的事了: 
    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();
            }
      

  4.   

    to:zxy98(孤独仙子)
    双击时,单元格变为可编辑,在单元格的值改变事件中写保存即可单元格的值改变事件是哪个
      

  5.   

    using System;
    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);
    } }
    }
    }
    }
      

  6.   

    http://www.cnblogs.com/iCeSnaker/archive/2004/07/31/29017.aspx
      

  7.   

    http://community.csdn.net/Expert/topic/3337/3337412.xml?temp=.2035028
      

  8.   

    双击datagrid某个单元格时,只是这个单元格可编辑,
    http://community.csdn.net/Expert/topic/3399/3399546.xml?temp=.6452295
      

  9.   

    可以使用 webgrid 来实现