Add items to list
dropboxId.Items.Add("ABC");
Add textbox value to drop down
dropboxId.Items.Add(txtId.Text);
Source Code
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="drpDwnDemo" runat="server" Height="16px" Width="133px">
<asp:ListItem Value="1">A</asp:ListItem>
<asp:ListItem Value="2">B</asp:ListItem>
<asp:ListItem Value="3">C</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="btnTest" runat="server" OnClick="btnTest_Click" Text="Check"
Style="font-weight: 700" />
<br />
<br />
HOW TO SELECT <b>VALUE</b> IN A DROP DOWM<br />
<asp:DropDownList ID="drpDwnDemo0" runat="server" Height="16px" Width="133px">
<asp:ListItem Value="1">A</asp:ListItem>
<asp:ListItem Value="2">B</asp:ListItem>
<asp:ListItem Value="3">C</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="btnValue" runat="server" OnClick="btnValue_Click" Text="Value"
Style="font-weight: 700" />
<asp:TextBox ID="txtValue" runat="server"></asp:TextBox>
<br />
<br />
<br />
<br />
HOW TO SELECT <b>TEXT</b> IN A DROP DOWM<br />
<asp:DropDownList ID="drpDwnDemo1" runat="server" Height="16px" Width="133px">
<asp:ListItem Value="1">A</asp:ListItem>
<asp:ListItem Value="2">B</asp:ListItem>
<asp:ListItem Value="3">C</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="btnText" runat="server" OnClick="btnText_Click" Text="TEXT"
Style="font-weight: 700" />
<asp:TextBox ID="txtText" runat="server"></asp:TextBox>
</div>
</form>
</body>
C# Codes
protected void btnTest_Click(object sender, EventArgs e)
{
if (drpDwnDemo.SelectedValue=="1")
{
Response.Write("<script>alert('A')</script>");//print message as script
}
else if (drpDwnDemo.SelectedValue == "2")
{
Response.Write("<script>alert('B')</script>");//print message as script
}
else if (drpDwnDemo.SelectedValue == "3")
{
Response.Write("<script>alert('C')</script>");//print message as script
}
}
protected void btnValue_Click(object sender, EventArgs e)
{
string value= drpDwnDemo0.SelectedValue;
txtValue.Text = value;
}
protected void btnText_Click(object sender, EventArgs e)
{
string value =Convert.ToString (drpDwnDemo1.SelectedItem);
txtText.Text = value;
}
dropboxId.Items.Add("ABC");
Add textbox value to drop down
dropboxId.Items.Add(txtId.Text);
Source Code
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="drpDwnDemo" runat="server" Height="16px" Width="133px">
<asp:ListItem Value="1">A</asp:ListItem>
<asp:ListItem Value="2">B</asp:ListItem>
<asp:ListItem Value="3">C</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="btnTest" runat="server" OnClick="btnTest_Click" Text="Check"
Style="font-weight: 700" />
<br />
<br />
HOW TO SELECT <b>VALUE</b> IN A DROP DOWM<br />
<asp:DropDownList ID="drpDwnDemo0" runat="server" Height="16px" Width="133px">
<asp:ListItem Value="1">A</asp:ListItem>
<asp:ListItem Value="2">B</asp:ListItem>
<asp:ListItem Value="3">C</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="btnValue" runat="server" OnClick="btnValue_Click" Text="Value"
Style="font-weight: 700" />
<asp:TextBox ID="txtValue" runat="server"></asp:TextBox>
<br />
<br />
<br />
<br />
HOW TO SELECT <b>TEXT</b> IN A DROP DOWM<br />
<asp:DropDownList ID="drpDwnDemo1" runat="server" Height="16px" Width="133px">
<asp:ListItem Value="1">A</asp:ListItem>
<asp:ListItem Value="2">B</asp:ListItem>
<asp:ListItem Value="3">C</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="btnText" runat="server" OnClick="btnText_Click" Text="TEXT"
Style="font-weight: 700" />
<asp:TextBox ID="txtText" runat="server"></asp:TextBox>
</div>
</form>
</body>
C# Codes
protected void btnTest_Click(object sender, EventArgs e)
{
if (drpDwnDemo.SelectedValue=="1")
{
Response.Write("<script>alert('A')</script>");//print message as script
}
else if (drpDwnDemo.SelectedValue == "2")
{
Response.Write("<script>alert('B')</script>");//print message as script
}
else if (drpDwnDemo.SelectedValue == "3")
{
Response.Write("<script>alert('C')</script>");//print message as script
}
}
protected void btnValue_Click(object sender, EventArgs e)
{
string value= drpDwnDemo0.SelectedValue;
txtValue.Text = value;
}
protected void btnText_Click(object sender, EventArgs e)
{
string value =Convert.ToString (drpDwnDemo1.SelectedItem);
txtText.Text = value;
}
No comments:
Post a Comment