Database
Id bigint(Auto increment)
value varchar(50)
Html Code
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Dropdownlist</title>
</head>
<body>
<form id="form1" runat="server">
<div width="300px" align="center">
<br />
<br />
<br />
<asp:DropDownList ID="dd" runat="server">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>6</asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="mm" runat="server">
<asp:ListItem>Jan</asp:ListItem>
<asp:ListItem>Feb</asp:ListItem>
<asp:ListItem>Mar</asp:ListItem>
<asp:ListItem>Apr</asp:ListItem>
<asp:ListItem>May</asp:ListItem>
<asp:ListItem>Jun</asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="yy" runat="server">
<asp:ListItem>2010</asp:ListItem>
<asp:ListItem>2011</asp:ListItem>
<asp:ListItem>2012</asp:ListItem>
<asp:ListItem>2013</asp:ListItem>
<asp:ListItem>2014</asp:ListItem>
<asp:ListItem>2015</asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
<br />
<br />
<br />
</div>
<div align="center" width="300px">
<asp:Button ID="btn" runat="server" Text="Submit" onclick="btn_Click" />
<br />
</div>
</form>
</body>
</html>
C# Code
using System;using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class dropdownlist : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("server=SANDEEP-PC;database=data;integrated security=true");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn_Click(object sender, EventArgs e)
{
string s = dd.Text + "/" + mm.Text + "/" + yy.Text;
SqlCommand cmd = new SqlCommand("insert into dropdown values('"+s+"')",con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
No comments:
Post a Comment