本文介绍了获取webform上动态控件的更改值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在更改动态控件的值,但是在静态按钮单击事件后无法获取这些值



我在页面加载时绑定动态控件这是

页面加载()
{
int id = 1;
//获取字段名称
cmd = new SqlCommand(GetDynamicFields,con);
con.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(@ DeviationID,SqlDbType.Int);
cmd.Parameters [@ DeviationID]。Value = id;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
dt = ds.Tables [0];
//获取字段值
cmd = new SqlCommand(GetDatafromXML,con);

cmd.CommandType = CommandType.StoredProcedure;
// xml
XmlReader reader = cmd.ExecuteXmlReader();
con.Close();

XmlDocument doc = new XmlDocument();
doc.Load(读者);
XmlElement rootElem = doc.DocumentElement;
if(dt.Rows.Count> 0)
{
for(int i = 0; i< rootElem.ChildNodes.Count; i ++)
{
string typedata = dt.Rows [i] [1] .ToString();
switch(typedata)
{
caseint:
casestring:
TextBox tx1 = new TextBox();
tx1.ID = dt.Rows [i] [0] .ToString();
tx1.Text = rootElem.ChildNodes [i] .InnerText;
td.Controls.Add(tx1);
tr.Controls.Add(td);
dynamictable.Controls.Add(tr);
Cache [tt] = tr;
休息;
casecombo:

string hh = rootElem.ChildNodes [i] .InnerText;
Ddl.Items.Add(hh);
td.Controls.Add(Ddl);
tr.Controls.Add(td);
dynamictable.Controls.Add(tr);
Cache [tt] = tr;
休息;
}
}
}
}



我尝试使用缓存来获取动态控件的更改值,但它显示我之前的值。因为它在页面加载事件中我希望。



那么我如何获得动态控件的更改值。

解决方案


I'm changing the values of dynamic controls, but not able to get those values after static button click event

I'm binding dynamic controls on page load here it is

page load()
{
   int id = 1;
                    //get field names
                    cmd = new SqlCommand("GetDynamicFields", con);
                    con.Open();
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@DeviationID", SqlDbType.Int);
                    cmd.Parameters["@DeviationID"].Value = id;
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    da.Fill(ds);
                    dt = ds.Tables[0];
                    //get field values
                    cmd = new SqlCommand("GetDatafromXML", con);

                    cmd.CommandType = CommandType.StoredProcedure;
                    //xml
                    XmlReader reader = cmd.ExecuteXmlReader();
                    con.Close();

                    XmlDocument doc = new XmlDocument();
                    doc.Load(reader);
                    XmlElement rootElem = doc.DocumentElement;
                    if (dt.Rows.Count > 0)
                    {
                        for (int i = 0; i < rootElem.ChildNodes.Count; i++)
                        {
                            string typedata = dt.Rows[i][1].ToString();
                            switch (typedata)
                            {
                                case "int":
                                case "string":
                                    TextBox tx1 = new TextBox();
                                    tx1.ID = dt.Rows[i][0].ToString();
                                       tx1.Text = rootElem.ChildNodes[i].InnerText;
                                    td.Controls.Add(tx1);
                                    tr.Controls.Add(td);
                                    dynamictable.Controls.Add(tr);
                                    Cache["tt"] = tr;
                                    break;
                                case "combo":

                                    string hh = rootElem.ChildNodes[i].InnerText;
                                    Ddl.Items.Add(hh);
                                    td.Controls.Add(Ddl);
                                    tr.Controls.Add(td);
                                    dynamictable.Controls.Add(tr);
                                    Cache["tt"] = tr;
                                    break;
                            }
                        }
                    }
}


And I tried using cache to get changed values of dynamic controls but it showing me previous values.because its in page load event i hope.

So how do i get the change values of dynamic controls.

解决方案



这篇关于获取webform上动态控件的更改值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 05:55