如何使用以下变量填充文本框 [英] How Do I Populate A Textbox With The Following Variable
问题描述
我的xml文件示例
< xmlScript xmlns.xsi =http // www.w3.org>
< greeting>
<数据>你好今天怎么样< / data>
< / greeting>
< confirm>
<数据>这是琼斯先生< / data>
< / confirm>
< / xmlScript>
//和等等
以下代码将xmlscripts保存到myscript中
string scriptpath = Server.MapPath(/ xmlScript /+ ddlxmlScriptList.SelectedValue.ToString()); //显示xml脚本的下拉列表(ddl)
xmlScript myscript = new xmlScript(scriptpath);
myscript = myscript.LoadFile();
if(myscript.greeting!= null)
{
我如何填充*文本框中的myscript问候语*
}
an example of my xml file
<xmlScript xmlns.xsi="http//www.w3.org">
<greeting >
< data > hi how you doing today < /data >
</greeting >
<confirm >
< data > is this Mr Jones < /data >
</confirm >
</xmlScript>
// and so on
the following code saves the xmlscripts into myscript
string scriptpath = Server.MapPath("/xmlScript/" + ddlxmlScriptList.SelectedValue.ToString()); // drop down list (ddl) displaying the xml scripts
xmlScript myscript = new xmlScript(scriptpath);
myscript = myscript.LoadFile();
if (myscript.greeting != null)
{
How do i populate *myscript greeting* in a textbox??
}
推荐答案
确定 - 在代码隐藏中你需要覆盖onInit方法:
Ok - in the code-behind you need to override the onInit method:
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
ddlxmlScriptList.SelectedValueChanged += XmlScriptListSelectedValueChanged;
}
然后,当更改下拉列值时,将运行方法'XmlScriptListSelectedValueChanged(object sender,EventArgs e)'。 />
我知道我可能说的有点低于你的水平。原谅我,但我喜欢完全完整的答案,你确实提出了一个非常通用的问题:)
我知道你知道这个,因为这可能是你的代码获取xml生活。
如果不是这样,那么也许你有一个按钮。同样的原则适用。只要您的页面仍然处于加载状态(例如当事件在后面的代码中运行时,即XmlScriptListSelectedValueChanged(sender,e))那么这是 where <和b> 你需要填充文本框。
填充文本框只是将字符串分配给文本框的Text属性:
Then, when the dropdown value is changed, the method 'XmlScriptListSelectedValueChanged(object sender, EventArgs e)' will run.
I know I am probably talking a bit below your level. Forgive me but I like fully complete answers and you did ask a very generic question :)
I know you know this because this is probably when your code to fetch the xml lives.
If that is not the case then perhaps you have a button. The same principle applies. As long as you have the page still in a loading state (such as when an event is running in the code behind, i.e. XmlScriptListSelectedValueChanged(sender,e)) then this is where and when you need to populate the text-box.
Populating the text-box is simply a case of assigning a string to the textbox's Text property:
XmlScriptListSelectedValueChanged(object sender, EventArgs e){
string theValueINeedInTheTextbox = SomeXmlLoadingStuff(ddlxmlScriptList.SelectedValue);
tbxTheTextbox.Text = theValueINeedInTheTextbox;
}
如果我已回答你的问题,请告诉我^ _ ^
Please let me know if I have answered your question ^_^
这篇关于如何使用以下变量填充文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!