<div class="row500">
<span class="cell200">
<asp:DropDownList ID="ddlCollision" runat="server" Height="28px" Width="354px" Style="font-size: 18px" OnSelectedIndexChanged="ddlCollision_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Value="0"></asp:ListItem>
<asp:ListItem Value="1">Cars</asp:ListItem>
<asp:ListItem Value="2">People</asp:ListItem>
</asp:DropDownList>
</span>
</div>
<br/>
<div class="row500" id="fixedObject" runat="server">
<span class="cell200">
<asp:Label ID="lblFixed" runat="server" Text="Car Label:"> </asp:Label>
</span>
<br />
<span class="cell200">
<asp:TextBox ID="TextBox9" runat="server"> </asp:TextBox>
</span>
</div>
我目前正在开发一个asp.net C#网页,其中包含一个下拉列表,其中大约有5个列表项,其值为0-4。每当用户选择其中一个项目时,我希望该数字与将出现的文本框的数量相对应。因此,如果用户从下拉列表中选择“2”,我需要显示/隐藏包含文本框的div并显示2个文本框。对此的任何帮助都会很棒!!!!
我的尝试: 下拉列表中的代码
protected void ddlCollision_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlCollision.SelectedValue == "1")
fixedObject.Visible = true;
else
fixedObject.Visible = false;
}
fixed object是包含文本框的div的id
答案 0 :(得分:0)
您甚至可以根据从下拉列表中选择的整数计数动态添加文本框。然后,对于那个et1 = (EditText)findViewById(R.id.editText);
et2 = (EditText)findViewById(R.id.editText2);
et3 = (EditText)findViewById(R.id.editText3);
et1.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if (getCurrentFocus() == et1) {
if (et1.getText().toString().equals("")) {
et2.setText("0");
et3.setText("0");
} else {
String s1 = et1.getText().toString();
Double d1 = Double.parseDouble(s1);
Double d3 = d1 * 12;
String s3 = Double.toString(d3);
et2.setText(s3);
Double d4 = d1 * 0.3048;
String s4 = Double.toString(d4);
et3.setText(s4);
}
}
}
@Override
public void afterTextChanged(Editable editable) {}
});
et2.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if (getCurrentFocus() == et2) {
if (et2.getText().toString().equals("")) {
et1.setText("0");
et3.setText("0");
} else {
String s1 = et2.getText().toString();
Double d1 = Double.parseDouble(s1);
Double d3 = d1 / 12;
String s3 = Double.toString(d3);
et1.setText(s3);
Double d4 = d1 * 39.40;
String s4 = Double.toString(d4);
et3.setText(s4);
}
}
@Override
public void afterTextChanged(Editable editable) {
}
});
et3.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2){
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if (getCurrentFocus() == et3) {
if (et3.getText().toString().equals("")) {
et2.setText("0");
et1.setText("0");
} else {
String s1 = et3.getText().toString();
Double d1 = Double.parseDouble(s1);
Double d3 = d1 * 39.40;
String s3 = Double.toString(d3);
et1.setText(s3);
Double d4 = d1 / 3.48;
String s4 = Double.toString(d4);
et3.setText(s4);
}
}
@Override
public void afterTextChanged(Editable editable) {}
});
}
次,它将运行并添加许多文本框。
static wrapClass(target, {hook = noop} = {}) {
return class wrapper extends target {
static get wrappedClass() {
return target;
}
constructor(...args) {
super(...Injector.fromParams(args).getDependencies(wrapper).concat(args));
}
}
count
答案 1 :(得分:0)
protected void ddlOptions_SelectedIndexChanged(object sender,EventArgs e) {
Int32 pickedValue = Int32.Parse(ddlOptions.SelectedValue);
Table table = new Table();
for (int i = 1; i <= pickedValue; i++)
{
TableRow row = new TableRow();
TableCell cell = new TableCell();
cell.Attributes.Add("runat", "server");
TextBox txt_splzn = new TextBox();
txt_splzn.ID = "txtB" + i.ToString();
txt_splzn.Text = "Text Number " + i.ToString();
cell.Controls.Add(txt_splzn);
row.Cells.Add(cell);
table.Rows.Add(row);
ctrlPlaceholder.Controls.Add(table);
}
}
}