我做了一个自定义控件,该控件从工具箱拉到web窗体后,界面出现的是一个有三列的table表,三个textBox,一个Button按钮,在自定义控件中我是用Render(HtmlTextWriter output)方法生成table表头及textbox,确定按钮.    现在要求是给该自定义组合控件拉到web窗体后,运行程序后,在textBox文本筐中输入字符串,按确定按钮,给table添加一行数据,每点一下按钮就给textBox中的值传到table中,使table多一行数据,请问怎么才能每点一次按钮,table中的数据多一行,在自定义控件中请问怎么实现啊,谢谢!急等,不明白需求,可问,我在线回答!!!

解决方案 »

  1.   

    Page不是有一个方法可以向页面注册一个处理添加的脚本,或者直接加那个社么IpostXXXXX的接口丢回来处理
      

  2.   

    高薪招聘.net资深工程师
    有兴趣者可把简历发动yanbq@shinetechchina.com,我们会及时给与回复,
    公司网址www.shinetechchina.com 工作地点(北京)
      

  3.   

    容易,先生成一个DataTable,添加的数据加入到这里面,然后绑定上去.
    不知道你怎么做的,所以这里假设通过一个DataTable绑定的!
    然后,每添加一个数据,就更新DataTable,然后重新绑定了!
    就这个思路,具体的方法按你的就行了!
      

  4.   

    public class CreateTable : System.Web.UI.UserControl
    {
    protected System.Web.UI.WebControls.TextBox Textbox2;
    protected System.Web.UI.WebControls.TextBox Textbox3;
    protected System.Web.UI.WebControls.Button bt_AddTable;
    protected System.Web.UI.WebControls.DataGrid dg_Display;
    protected System.Web.UI.WebControls.TextBox TextBox1; private DataTable dt = new DataTable(); private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    if (this.IsPostBack)
    {
    if (null == this.Session["DT"])
    {
    dt.Columns.Add("Name");
    dt.Columns.Add("Address");
    dt.Columns.Add("Phone");
    }
    else
    {
    dt = (DataTable)this.Session["DT"];
    }
    }
    } private void bt_AddTable_Click(object sender, System.EventArgs e)
    {
    DataRow row = dt.NewRow();
    row["Name"] = this.TextBox1.Text;
    row["Address"] = this.Textbox2.Text;
    row["Phone"] = this.Textbox3.Text;
    dt.Rows.Add(row);
    this.dg_Display.DataSource = dt.DefaultView;
    this.dg_Display.DataBind();
    this.Session["DT"] = dt;
    }
    }
      

  5.   


    ??????????????????????????????????????????????????????
    楼上兄弟,我做的是自定义web控件啊,你提供的是在web窗体下实现的吧??
    你可看下我贴子的问题说明,不过还是谢谢兄弟的费心,希望你能继续跟踪这贴,谢谢
      

  6.   

    实现的是WEB用户控件,注意这里:public class CreateTable : System.Web.UI.UserControl
    你先在机器上试下先!
      

  7.   

    额错列!额真地错列!原来是自定义的!这里先!public class Rendered : Control, IPostBackDataHandler, IPostBackEventHandler
    {
    private String text = "Please Enter the Name,Address and Phone!";
    private string name;
    private string address;
    private string phone; private string[] temp = new string[3];
    private ArrayList list = new ArrayList(); public ArrayList List
    {
    get
    {
    return list;
    }
    set
    {
    list = value;
    }
    }
          
    public String Text 
    {
    get 
    {
    return text;
    }
    set 

    text = value;
    }        
    }
          
    public event CheckEventHandler Check;
          
    protected virtual void OnCheck(CheckEventArgs ce)
    {
    if (Check != null)
    {
    Check(this,ce);
    }
    }
          
    public virtual bool LoadPostData(string postDataKey, 
    NameValueCollection values) 
    {
    name = values[UniqueID + "_name"];
    address = values[UniqueID + "_address"];
    phone = values[UniqueID + "_phone"]; temp[0] = name;
    temp[1] = address;
    temp[2] = phone;
    list.Add(temp); Page.RegisterRequiresRaiseEvent(this);
    return false;
    } public virtual void RaisePostDataChangedEvent() 
    {
    }
          
    public void RaisePostBackEvent(string eventArgument)
    {         
    OnCheck(new CheckEventArgs());
    }
          
          
    protected override void Render(HtmlTextWriter output) 
    {
    string strOut = "<table align=center runat=server>" + 
    "<p>" + Text + "</p>" + 
    "<tr><td><input type=text name=" + this.UniqueID + "_name" + "></td>" + 
    "<td><input type=text name=" + this.UniqueID + "_address" + "></td>" + 
    "<td><input type=text name=" + this.UniqueID + "_phone" + "></td>" + 
    "<td><input type=submit name=" + this.UniqueID + " value='Submit' runat=server></td>" + 
    "</tr>" +
    "</table>" +
    "<table align=center runat=server border=1>" +
    "<tr><td>Name</td><td>Address</td><td>Phone</td></tr>";
    for (int i = 0; i < List.Count; i++)
    {
    string[] tempStrs = (string[])List[i];
    strOut += "<tr><td>" + tempStrs[0] + "</td><td>" + tempStrs[1] + "</td><td>" + tempStrs[2] + "</td></tr>";
    }
    strOut += "</table>";

    output.Write(strOut);
    }
    } public class CheckEventArgs : EventArgs
    {       
    public CheckEventArgs()
    {
    }
    }
          
    public delegate void CheckEventHandler(object sender, CheckEventArgs ce);
      

  8.   

    客户端:
    private void Page_Load(object sender, System.EventArgs e)
    {

    if (this.Session["list"] != null)
    {
    ArrayList tempList = (ArrayList)this.Session["list"];
    for (int i = 0; i < tempList.Count; i++)
    {
    uc_Table.List.Add(tempList[i]);
    }
    }
    }
    private void uc_Table_Check(object sender, MyApplication.CheckEventArgs ce)
    {
    this.Session["list"] = uc_Table.List;
    uc_Table.Text = "<h2> You can enter more ! </h2>";
    }