谢谢,请问一下怎么联系kotao_78 ?

解决方案 »

  1.   

    做过一个类似的程序,可能不一样
    代码全给你,看着办吧!//mibaomin
    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.Data.SqlClient;namespace KMSWebApp
    {
    /// <summary>
    /// SortManager 的摘要说明。
    /// </summary>
    public class SortManager : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.DataGrid DataGrid1;
    protected System.Web.UI.WebControls.Button bt_Add;
    protected System.Web.UI.WebControls.Label lb_Sort;
    protected System.Web.UI.WebControls.Button bt_Cancel;
    protected System.Web.UI.WebControls.Button bt_Submit;

    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    if(!IsPostBack)
    {
    //此代码是传进来的参数
    ViewState["sort"]=Request.QueryString["sort"].ToString();
    //ViewState["sort"]="收文类型";
    BindGrid();
    DisableDataGrid();
    bt_Submit.Enabled=false;
    bt_Cancel.Enabled=false;

    }
    } #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.bt_Add.Click += new System.EventHandler(this.bt_Add_Click);
    this.bt_Submit.Click += new System.EventHandler(this.bt_Submit_Click);
    this.bt_Cancel.Click += new System.EventHandler(this.bt_Cancel_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void DisableDataGrid()
    {
    foreach(DataGridItem dgi in DataGrid1.Items)
    {
    TextBox tb=(TextBox)(dgi.Cells[1].Controls[1]);
    tb.Enabled=false;
    }            
    } private void EnableDataGrid()
    {
    foreach(DataGridItem dgi in DataGrid1.Items)
    {
    TextBox tb=(TextBox)(dgi.Cells[1].Controls[1]);
    tb.Enabled=true;
    }
    } private void BindGrid()
    {
    string sort=ViewState["sort"].ToString();
    string sql="select iId,cParamValue from t_EnumType where bDel=0 and cParamDescription='"+sort+"' order by iId Desc";//+Session["Sort"];
    DataSet ds=publicClass.DataBase.ReturnDataSet(sql);
    ViewState["ds"]=ds;
    DataView myview=ds.Tables[0].DefaultView;
    DataGrid1.DataSource=myview;
    DataGrid1.DataBind();     
    } private void bt_Submit_Click(object sender, System.EventArgs e)
    {
    DataGridItem dgi = DataGrid1.Items[0];
    string Description=ViewState["sort"].ToString();
    string Value=((TextBox)dgi.Cells[1].Controls[1]).Text.Trim();
    if(Value!=""&&Value!=null)
    {
    string sql="insert t_EnumType(cParamDescription,cParamValue,bDel) values('"+Description+"','"+Value+"',0)"; 
    try
    {
                        publicClass.DataBase.ModifyData(sql);
    }
    catch
    {
                        publicClass.ShowDialog("类型名称已经存在!",this);
    }
    BindGrid();
    bt_Add.Enabled=true;
    bt_Cancel.Enabled=false;
    bt_Submit.Enabled=false;
    DisableDataGrid();
    Response.Write("<script>if (window.opener!=null) window.opener.location.href=window.opener.location.href;</script>");
    }
    else
    {
    publicClass.ShowDialog("添加失败!类别名称不能为空值!!",this);
    }
    } private void bt_Add_Click(object sender, System.EventArgs e)
    {
    DataSet ds=(DataSet)ViewState["ds"];
    DataRow newrow=ds.Tables[0].NewRow();
    newrow[0]=0;
    newrow[1]="";
    ds.Tables[0].Rows.InsertAt(newrow,0);
    DataGrid1.DataSource=ds.Tables[0].DefaultView;
    DataGrid1.DataBind(); bt_Submit.Enabled=true;
    bt_Cancel.Enabled=true;
    bt_Add.Enabled =false;

    DisableDataGrid();
    TextBox tb=(TextBox)(DataGrid1.Items[0].Cells[1].Controls[1]);
    tb.Enabled=true;
    } private void bt_Cancel_Click(object sender, System.EventArgs e)
    {
    BindGrid();
    bt_Submit.Enabled=false;
    bt_Cancel.Enabled=false;
    bt_Add.Enabled =true;
    DisableDataGrid();
    }

    }
    }
      

  2.   

    做过一个类似的程序,可能不一样
    代码全给你,看着办吧!//mibaomin
    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.Data.SqlClient;namespace KMSWebApp
    {
    /// <summary>
    /// SortManager 的摘要说明。
    /// </summary>
    public class SortManager : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.DataGrid DataGrid1;
    protected System.Web.UI.WebControls.Button bt_Add;
    protected System.Web.UI.WebControls.Label lb_Sort;
    protected System.Web.UI.WebControls.Button bt_Cancel;
    protected System.Web.UI.WebControls.Button bt_Submit;

    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    if(!IsPostBack)
    {
    //此代码是传进来的参数
    ViewState["sort"]=Request.QueryString["sort"].ToString();
    //ViewState["sort"]="收文类型";
    BindGrid();
    DisableDataGrid();
    bt_Submit.Enabled=false;
    bt_Cancel.Enabled=false;

    }
    } #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.bt_Add.Click += new System.EventHandler(this.bt_Add_Click);
    this.bt_Submit.Click += new System.EventHandler(this.bt_Submit_Click);
    this.bt_Cancel.Click += new System.EventHandler(this.bt_Cancel_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void DisableDataGrid()
    {
    foreach(DataGridItem dgi in DataGrid1.Items)
    {
    TextBox tb=(TextBox)(dgi.Cells[1].Controls[1]);
    tb.Enabled=false;
    }            
    } private void EnableDataGrid()
    {
    foreach(DataGridItem dgi in DataGrid1.Items)
    {
    TextBox tb=(TextBox)(dgi.Cells[1].Controls[1]);
    tb.Enabled=true;
    }
    } private void BindGrid()
    {
    string sort=ViewState["sort"].ToString();
    string sql="select iId,cParamValue from t_EnumType where bDel=0 and cParamDescription='"+sort+"' order by iId Desc";//+Session["Sort"];
    DataSet ds=publicClass.DataBase.ReturnDataSet(sql);
    ViewState["ds"]=ds;
    DataView myview=ds.Tables[0].DefaultView;
    DataGrid1.DataSource=myview;
    DataGrid1.DataBind();     
    } private void bt_Submit_Click(object sender, System.EventArgs e)
    {
    DataGridItem dgi = DataGrid1.Items[0];
    string Description=ViewState["sort"].ToString();
    string Value=((TextBox)dgi.Cells[1].Controls[1]).Text.Trim();
    if(Value!=""&&Value!=null)
    {
    string sql="insert t_EnumType(cParamDescription,cParamValue,bDel) values('"+Description+"','"+Value+"',0)"; 
    try
    {
                        publicClass.DataBase.ModifyData(sql);
    }
    catch
    {
                        publicClass.ShowDialog("类型名称已经存在!",this);
    }
    BindGrid();
    bt_Add.Enabled=true;
    bt_Cancel.Enabled=false;
    bt_Submit.Enabled=false;
    DisableDataGrid();
    Response.Write("<script>if (window.opener!=null) window.opener.location.href=window.opener.location.href;</script>");
    }
    else
    {
    publicClass.ShowDialog("添加失败!类别名称不能为空值!!",this);
    }
    } private void bt_Add_Click(object sender, System.EventArgs e)
    {
    DataSet ds=(DataSet)ViewState["ds"];
    DataRow newrow=ds.Tables[0].NewRow();
    newrow[0]=0;
    newrow[1]="";
    ds.Tables[0].Rows.InsertAt(newrow,0);
    DataGrid1.DataSource=ds.Tables[0].DefaultView;
    DataGrid1.DataBind(); bt_Submit.Enabled=true;
    bt_Cancel.Enabled=true;
    bt_Add.Enabled =false;

    DisableDataGrid();
    TextBox tb=(TextBox)(DataGrid1.Items[0].Cells[1].Controls[1]);
    tb.Enabled=true;
    } private void bt_Cancel_Click(object sender, System.EventArgs e)
    {
    BindGrid();
    bt_Submit.Enabled=false;
    bt_Cancel.Enabled=false;
    bt_Add.Enabled =true;
    DisableDataGrid();
    }

    }
    }
      

  3.   

    你是想用DATAGRID完成还是TABLE(HTML)的?
      

  4.   

    问题是在什么时候什么地方保存?
    动态创建的Table一提交就清空了,怎么保存呢? 请教!!!
      

  5.   

    用DataGrid或者DataList不可以吗?
      

  6.   

    那只要在客户端用javascript,用innerhtml动态的添加了。应该很好写的
      

  7.   

    你把datatable保存到一个dataview不就行了
      

  8.   

    已经改成用DataGrid实现了,点击“Add”按钮就添加一空行,想省去“Add”按钮应该怎么做呢?