Add Items or Value to DropDownList
Add Textbox Text Items or Value to Dropdownlist in Jquery & C# Coding in Dynamically Using Asp.Net C#.
DEMO
Download
HTML Coding
C# Coding
Next - Add to Jquery Plugin & Append Textbox Text to Dropdownlist
Next - Add To C# Coding in Button Onclick Mode
Add Textbox Text Items or Value to Dropdownlist in Jquery & C# Coding in Dynamically Using Asp.Net C#.
DEMO
Download
HTML Coding
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Add items to dropdownlist in asp.net using jquery</title>
<script src="jquery.min.js"></script>
<script>
$(document).ready(function () {
$('#btn_add').click(function () {
$('#ddlCourse').append(
$('<option></option>').text($('#txtCourse').val()));
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div align="center">
<asp:TextBox ID="txtCourse" runat="server"></asp:TextBox>
<br />
<asp:Button ID="btn_add" runat="server" Text="Add Item Jquery" />
<asp:Button ID="Button1" runat="server" Text="Add Item C#" OnClick="Button1_Click" />
<br />
<asp:DropDownList ID="ddlCourse" runat="server">
<asp:ListItem Text="Select
Course"></asp:ListItem>
</asp:DropDownList>
</div>
</form>
</body>
</html>
C# Coding
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
ddlCourse.Items.Add(txtCourse.Text);
}
}
Add New Web Form - Select Textbox,Dropdownlist Form Toolbox
Next - Add to Jquery Plugin & Append Textbox Text to Dropdownlist
Next - Add To C# Coding in Button Onclick Mode
0 comments:
Post a Comment