我想創建5個文本框下拉選定的索引更改創建和4個文本框創建如果下拉索引是4.下拉是在asp.net updatepanel。更新面板中還有一個按鈕。當用戶點擊該按鈕時,無論在文本框中輸入什麼,都會顯示在標籤上。下拉的selectedindex動態文本框
請建議我的解決方案。
我想創建5個文本框下拉選定的索引更改創建和4個文本框創建如果下拉索引是4.下拉是在asp.net updatepanel。更新面板中還有一個按鈕。當用戶點擊該按鈕時,無論在文本框中輸入什麼,都會顯示在標籤上。下拉的selectedindex動態文本框
請建議我的解決方案。
五月這項工作
<div>
</div><asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Panel ID="Panel1" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"
onselectedindexchanged="DropDownList1_SelectedIndexChanged"><asp:ListItem Value="1">one </asp:ListItem><asp:ListItem Value="2">Two </asp:ListItem><asp:ListItem Value="3">Three </asp:ListItem><asp:ListItem Value="4">Four</asp:ListItem>
</asp:DropDownList>
<br />
<asp:Button ID="Button2" runat="server" Text="fectchText" onclick="Button2_Click" />
<br />
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
<br />
<br />
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</ContentTemplate>
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
if (ViewState["mode"].ToString() == "1")
createTextbox();
ViewState.Add("mode", "1");
}
else
{
ViewState.Add("mode", "0");
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
createTextbox();
}
public void createTextbox()
{
int noOftextbox = Convert.ToInt32(DropDownList1.SelectedItem.Value);
for (int i = 0; i < noOftextbox; i++)
{
TextBox txtbox = new TextBox();
txtbox.ID = "txt" + i;
txtbox.Visible = true;
txtbox.Height = 30;
txtbox.Width = 100;
UpdatePanel1.ContentTemplateContainer.Controls.Add(txtbox);
PlaceHolder1.Controls.Add(txtbox);
}
}
protected void Button2_Click(object sender, EventArgs e)
{
int nocount= Convert.ToInt32(DropDownList1.SelectedItem.Value);
for (int count = 0; count <= nocount-1 ; count++)
{
TextBox txtRead = (TextBox)PlaceHolder1.FindControl("txt" + (count));
Label1.Text += txtRead.Text+"-";
}
}
你可以試試這個.....
for (int i = 0; i < ddlTest.SelectedIndex; i++)
{
TextBox txt = new TextBox();
txt.ID = "txt" + i.ToString();
PlaceHolder1.Controls.Add(txt);
}
更改ddlTest.SelectedIndex你的循環條件.....
赫斯的解決方案裏面創建的UpdatePanel txtbox
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Panel ID="Panel1" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="False">
<asp:ListItem Value="1">one </asp:ListItem><asp:ListItem Value="2">Two </asp:ListItem><asp:ListItem Value="3">Three </asp:ListItem><asp:ListItem Value="4">Four</asp:ListItem>
</asp:DropDownList>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
protected void Button1_Click(object sender, EventArgs e)
{
int noOftextbox =Convert.ToInt32(DropDownList1.SelectedItem.Value);
for (int i = 0; i < noOftextbox; i++)
{
TextBox txtbox = new TextBox();
txtbox.ID = i.ToString();
txtbox.Visible = true;
txtbox.Height = 30;
txtbox.Width = 100;
txtbox.Text = "txt" + i.ToString();
PlaceHolder1.Controls.Add(txtbox);
//UpdatePanel1.Controls.Add(txtbox);
//UpdatePanel1.Controls.Add(new LiteralControl("<br/>"));
}
}
感謝您的回覆。如何獲取用戶輸入的值? – DotnetSparrow 2012-04-02 07:09:30
在標籤中輸入txt(運行時創建的)值? – 2012-04-02 07:10:52
我的意思是用戶將在這些動態文本框中輸入任何內容,並且會有另一個按鈕和標籤。用戶可以單擊該按鈕,這些動態文本框中的值類型應該出現在標籤 – DotnetSparrow 2012-04-02 07:12:49
你可以試試這個...
//Add Control into Panel
for (int i = 0; i < 5; i++)
{
TextBox txt = new TextBox();
txt.ID = "txt" + i.ToString();
txt.Text = "this is text:" + i.ToString();
pnlTest.Controls.Add(txt);
}
//Fetch Value from Panel
for (int i = 0; i < pnlTest.Controls.Count; i++)
{
string val = ((TextBox)pnlTest.Controls[i]).Text;
}
首先回路添加動態控制到面板,另一個迴路獲取對照值的....
嗨Manoj:它不起作用的更新面板,因爲updatepanel停止回發 – DotnetSparrow 2012-04-02 07:19:51
嗨... 請嘗試這應該工作,因爲我也做到了我的申請... 你可能會錯過那裏的東西。 – 2012-04-02 07:23:53
嗨MAnoj:它無法在updatepanel內工作:( – DotnetSparrow 2012-04-02 07:33:08
如何訪問值用戶將鍵入這些文本框和這些控件(dropdownlist an d動態文本框)需要位於ajax updatepanel – DotnetSparrow 2012-04-02 06:52:01