处理表单字段更改 - 事件? [英] Handling Form Field Changes - Events?

查看:104
本文介绍了处理表单字段更改 - 事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个aspx页面,我根据数据集对两个下拉列表进行数据绑定(数据是从XML文档加载的)。字段得到正确更新,没有问题。我的问题是:你如何处理事件,以便如果用户在下拉列表中选择一个选项,它会在第二个下拉列表中显示相应的值?


我一直在分裂这个问题,而且我需要社区帮助。以下是我正在使用的代码:


testpage.aspx:

< asp:DropDownList id =" client" runat =" server">

< asp:DropDownList id =" wsname" runat =" server">

testpage.aspx.cs

private void populate_fields()

{

DataSet ds = new DataSet();

ds.ReadXml(Server.MapPath(" params.xml"));


this.client。 DataSource = ds.Tables [0];

this.client.DataTextField = ds.Tables [0] .Columns [0] .ToString();

this.client .DataBind();


this.wsname.DataSource = ds.Tables [0];

this.wsname.DataTextField = ds.Tables [0] .Columns [1] .ToString();

this.wsname.DataBind();


}

params.xml

<?xml version =" 1.0" encoding =" UTF-8"?>

< clientList xmlns:xsi =" http://www.w3.org/2001/XMLSchema-instance">

< client>

< name> Client1< / name>

< webservicename> WebServiceName1< / webservicename>

< / client>

< client>

< name> Client2< / name>

< webservicename> WebServiceName2< / webservicename> ;

< / client>

< / clientList>

任何帮助都会受到高度重视。


问候


Matthew Workman


I have one aspx page where i am databinding two drop down lists based on a dataset (the data is being loaded from an XML Document). The fields get updated properly, no problem there. My question is: "How do you handle the events so that if the user chooses an option in the drop down, it poulates the cooresponding value in the second drop down?"

I have been splitting hairs on this, and I am at a point that I need some help from the community. Here is a look at the code I am using:

testpage.aspx:
<asp:DropDownList id="client" runat="server">
<asp:DropDownList id="wsname" runat="server">
testpage.aspx.cs
private void populate_fields()
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("params.xml"));

this.client.DataSource = ds.Tables[0];
this.client.DataTextField =ds.Tables[0].Columns[0].ToString();
this.client.DataBind();

this.wsname.DataSource = ds.Tables[0];
this.wsname.DataTextField =ds.Tables[0].Columns[1].ToString();
this.wsname.DataBind();

}
params.xml
<?xml version="1.0" encoding="UTF-8"?>
<clientList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<client>
<name>Client1</name>
<webservicename>WebServiceName1</webservicename>
</client>
<client>
<name>Client2</name>
<webservicename>WebServiceName2</webservicename>
</client>
</clientList>
Any help would be highly cherished.

Regards

Matthew Workman

推荐答案

如果下拉菜单设置为AutoPostBack,则''SelectedIndexChanged''服务器端事件触发和你的页面PostBack',你可以将第二个下拉列表的selectedIndex属性设置为第一个下拉列表的selectedIndex属性。看起来索引应该匹配,因为它们是从数据源表中的同一行加载的。


对用户来说可能更快的另一种方法是使用Javascript客户端 - 因为你不需要从服务器获得更多数据,所以也可以做同样的事情。


-Darrin

" Matthew Workman" <二******* @ hotmail.com>在消息新闻中写道:eD ************** @ tk2msftngp13.phx.gbl ...

我有一个aspx页面,我在数据绑定两个基于数据集的下拉列表(数据从XML文档加载)。字段得到正确更新,没有问题。我的问题是:你如何处理事件,以便如果用户在下拉列表中选择一个选项,它会在第二个下拉列表中显示相应的值?


我一直在分裂这个问题,而且我需要社区帮助。以下是我正在使用的代码:


testpage.aspx:

< asp:DropDownList id =" client" runat =" server">

< asp:DropDownList id =" wsname" runat =" server">

testpage.aspx.cs

private void populate_fields()

{

DataSet ds = new DataSet();

ds.ReadXml(Server.MapPath(" params.xml"));


this.client。 DataSource = ds.Tables [0];

this.client.DataTextField = ds.Tables [0] .Columns [0] .ToString();

this.client .DataBind();


this.wsname.DataSource = ds.Tables [0];

this.wsname.DataTextField = ds.Tables [0] .Columns [1] .ToString();

this.wsname.DataBind();


}

params.xml

<?xml version =" 1.0" encoding =" UTF-8"?>

< clientList xmlns:xsi =" http://www.w3.org/2001/XMLSchema-instance">

< client>

< name> Client1< / name>

< webservicename> WebServiceName1< / webservicename>

< / client>

< client>

< name> Client2< / name>

< webservicename> WebServiceName2< / webservicename> ;

< / client>

< / clientList>

任何帮助都会受到高度重视。


问候


Matthew Workman
If the dropdowns are set to AutoPostBack, when the ''SelectedIndexChanged'' server-side event fires and your page PostBack''s, you can set the second dropdown''s selectedIndex property to the selectedIndex property of the first dropdown. It appears the index''s should match since they are loaded from the same row in the datasource table.

Another way that may be quicker for the user would be to use Javascript client-side to do the same thing since you don''t have to get any more data from the server.

-Darrin
"Matthew Workman" <di*******@hotmail.com> wrote in message news:eD**************@tk2msftngp13.phx.gbl...

I have one aspx page where i am databinding two drop down lists based on a dataset (the data is being loaded from an XML Document). The fields get updated properly, no problem there. My question is: "How do you handle the events so that if the user chooses an option in the drop down, it poulates the cooresponding value in the second drop down?"

I have been splitting hairs on this, and I am at a point that I need some help from the community. Here is a look at the code I am using:

testpage.aspx:
<asp:DropDownList id="client" runat="server">
<asp:DropDownList id="wsname" runat="server">
testpage.aspx.cs
private void populate_fields()
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("params.xml"));

this.client.DataSource = ds.Tables[0];
this.client.DataTextField =ds.Tables[0].Columns[0].ToString();
this.client.DataBind();

this.wsname.DataSource = ds.Tables[0];
this.wsname.DataTextField =ds.Tables[0].Columns[1].ToString();
this.wsname.DataBind();

}
params.xml
<?xml version="1.0" encoding="UTF-8"?>
<clientList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<client>
<name>Client1</name>
<webservicename>WebServiceName1</webservicename>
</client>
<client>
<name>Client2</name>
<webservicename>WebServiceName2</webservicename>
</client>
</clientList>
Any help would be highly cherished.

Regards

Matthew Workman


如果下拉菜单设置为AutoPostBack,那么''SelectedIndexChanged''服务器-side事件触发和你的页面PostBack',你可以将第二个下拉列表的selectedIndex属性设置为第一个下拉列表的selectedIndex属性。看起来索引应该匹配,因为它们是从数据源表中的同一行加载的。


对用户来说可能更快的另一种方法是使用Javascript客户端 - 因为你不需要从服务器获得更多数据,所以也可以做同样的事情。


-Darrin

" Matthew Workman" <二******* @ hotmail.com>在消息新闻中写道:eD ************** @ tk2msftngp13.phx.gbl ...

我有一个aspx页面,我在数据绑定两个基于数据集的下拉列表(数据从XML文档加载)。字段得到正确更新,没有问题。我的问题是:你如何处理事件,以便如果用户在下拉列表中选择一个选项,它会在第二个下拉列表中显示相应的值?


我一直在分裂这个问题,而且我需要社区帮助。以下是我正在使用的代码:


testpage.aspx:

< asp:DropDownList id =" client" runat =" server">

< asp:DropDownList id =" wsname" runat =" server">

testpage.aspx.cs

private void populate_fields()

{

DataSet ds = new DataSet();

ds.ReadXml(Server.MapPath(" params.xml"));


this.client。 DataSource = ds.Tables [0];

this.client.DataTextField = ds.Tables [0] .Columns [0] .ToString();

this.client .DataBind();


this.wsname.DataSource = ds.Tables [0];

this.wsname.DataTextField = ds.Tables [0] .Columns [1] .ToString();

this.wsname.DataBind();


}

params.xml

<?xml version =" 1.0" encoding =" UTF-8"?>

< clientList xmlns:xsi =" http://www.w3.org/2001/XMLSchema-instance">

< client>

< name> Client1< / name>

< webservicename> WebServiceName1< / webservicename>

< / client>

< client>

< name> Client2< / name>

< webservicename> WebServiceName2< / webservicename> ;

< / client>

< / clientList>

任何帮助都会受到高度重视。


问候


Matthew Workman
If the dropdowns are set to AutoPostBack, when the ''SelectedIndexChanged'' server-side event fires and your page PostBack''s, you can set the second dropdown''s selectedIndex property to the selectedIndex property of the first dropdown. It appears the index''s should match since they are loaded from the same row in the datasource table.

Another way that may be quicker for the user would be to use Javascript client-side to do the same thing since you don''t have to get any more data from the server.

-Darrin
"Matthew Workman" <di*******@hotmail.com> wrote in message news:eD**************@tk2msftngp13.phx.gbl...

I have one aspx page where i am databinding two drop down lists based on a dataset (the data is being loaded from an XML Document). The fields get updated properly, no problem there. My question is: "How do you handle the events so that if the user chooses an option in the drop down, it poulates the cooresponding value in the second drop down?"

I have been splitting hairs on this, and I am at a point that I need some help from the community. Here is a look at the code I am using:

testpage.aspx:
<asp:DropDownList id="client" runat="server">
<asp:DropDownList id="wsname" runat="server">
testpage.aspx.cs
private void populate_fields()
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("params.xml"));

this.client.DataSource = ds.Tables[0];
this.client.DataTextField =ds.Tables[0].Columns[0].ToString();
this.client.DataBind();

this.wsname.DataSource = ds.Tables[0];
this.wsname.DataTextField =ds.Tables[0].Columns[1].ToString();
this.wsname.DataBind();

}
params.xml
<?xml version="1.0" encoding="UTF-8"?>
<clientList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<client>
<name>Client1</name>
<webservicename>WebServiceName1</webservicename>
</client>
<client>
<name>Client2</name>
<webservicename>WebServiceName2</webservicename>
</client>
</clientList>
Any help would be highly cherished.

Regards

Matthew Workman


这有很大的帮助...


关于这个的一个简单问题,你会建议什么来控制那个实际帖子上执行的代码呢?现在当发回的帖子是通过Page_Load并查看它是否是post(Page.IsPostBack)然后执行页面上的所有代码。如果我只想更新一个字段,我想尽量避免所有其余的代码。有什么想法吗?


非常感谢。


马修。


Darrin J Olson ; <哒************ @ sio.midco.net>在消息新闻中写道:eH ************* @ TK2MSFTNGP12.phx.gbl ...

如果下拉菜单设置为AutoPostBack,则为''SelectedIndexChanged' '服务器端事件触发和你的页面PostBack',你可以将第二个下拉列表的selectedIndex属性设置为第一个下拉列表的selectedIndex属性。看起来索引应该匹配,因为它们是从数据源表中的同一行加载的。


对用户来说可能更快的另一种方法是使用Javascript客户端 - 因为你不需要从服务器获得更多数据,所以也可以做同样的事情。


-Darrin

" Matthew Workman" <二******* @ hotmail.com>在消息新闻中写道:eD ************** @ tk2msftngp13.phx.gbl ...

我有一个aspx页面,我在数据绑定两个基于数据集的下拉列表(数据从XML文档加载)。字段得到正确更新,没有问题。我的问题是:你如何处理事件,以便如果用户在下拉列表中选择一个选项,它会在第二个下拉列表中显示相应的值?


我一直在分裂这个问题,而且我需要社区帮助。以下是我正在使用的代码:


** Snip **

That is helping a lot...

One quick question on this, what would you recommend for controlling what code is executed on that actual post back then? Right now when the post back occurs is goes through the Page_Load and looks at whether or not it was post (Page.IsPostBack) then executes all the code on the page. If I want to update just a single field, I want to try to avoid all the rest of the code. Any thoughts?

Thanks a bunch.

Matthew.

"Darrin J Olson" <da************@sio.midco.net> wrote in message news:eH*************@TK2MSFTNGP12.phx.gbl...
If the dropdowns are set to AutoPostBack, when the ''SelectedIndexChanged'' server-side event fires and your page PostBack''s, you can set the second dropdown''s selectedIndex property to the selectedIndex property of the first dropdown. It appears the index''s should match since they are loaded from the same row in the datasource table.

Another way that may be quicker for the user would be to use Javascript client-side to do the same thing since you don''t have to get any more data from the server.

-Darrin
"Matthew Workman" <di*******@hotmail.com> wrote in message news:eD**************@tk2msftngp13.phx.gbl...

I have one aspx page where i am databinding two drop down lists based on a dataset (the data is being loaded from an XML Document). The fields get updated properly, no problem there. My question is: "How do you handle the events so that if the user chooses an option in the drop down, it poulates the cooresponding value in the second drop down?"

I have been splitting hairs on this, and I am at a point that I need some help from the community. Here is a look at the code I am using:

**Snip**


这篇关于处理表单字段更改 - 事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆