我做了一个自定义控件,该控件从工具箱拉到web窗体后,界面出现的是一个有三列的table表,三个textBox,一个Button按钮,在自定义控件中我是用Render(HtmlTextWriter output)方法生成table表头及textbox,确定按钮. 现在要求是给该自定义组合控件拉到web窗体后,运行程序后,在textBox文本筐中输入字符串,按确定按钮,给table添加一行数据,每点一下按钮就给textBox中的值传到table中,使table多一行数据,请问怎么才能每点一次按钮,table中的数据多一行,在自定义控件中请问怎么实现啊,谢谢!急等,不明白需求,可问,我在线回答!!!
解决方案 »
- dr.GetString(dr.GetOrdinal(""))问题
- 求高手解答
- 求一个匹配url且不包含一个指定url的正则
- 怎么实现如下方式的远程数据接收?(项目需要,急)
- System.Windows.Forms.WebBrowser() 相关简单问题
- 高人请进 :关于 调用非托管函数 的 回调函数
- [研究]不规则坐标(可看作二维数组)分组算法。欢迎所有有兴趣研究算法的人。
- webBrowser使用问题
- 请大家帮帮忙!!!在c# 中如何记录离开网站的时间
- 我遇到的问题,大家帮忙!50分在线等!
- 急请!!!各版主和高手朋友帮解决:按时间统计次数问题,急等!!!
- !!!急请 &&版主&& 和 ###高手###兄弟!帮解决或一起探讨获取datagrid绑定的字段名问题,困惑很久,自认为比较棘手的问题,在线等待!
有兴趣者可把简历发动yanbq@shinetechchina.com,我们会及时给与回复,
公司网址www.shinetechchina.com 工作地点(北京)
不知道你怎么做的,所以这里假设通过一个DataTable绑定的!
然后,每添加一个数据,就更新DataTable,然后重新绑定了!
就这个思路,具体的方法按你的就行了!
{
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;
}
}
??????????????????????????????????????????????????????
楼上兄弟,我做的是自定义web控件啊,你提供的是在web窗体下实现的吧??
你可看下我贴子的问题说明,不过还是谢谢兄弟的费心,希望你能继续跟踪这贴,谢谢
你先在机器上试下先!
{
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);
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>";
}