Está en la página 1de 5

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

sql table for dynamic list item

create database skk90


use skk90
create table tblinfo(
id int primary key identity(1,1),
Name varchar (30),
Gender varchar (40),
Country varchar (40),
Occupation varchar(80))

select*from tblinfo
select*from tblcountry
select*from tbloccupation

create table tblcountry(


id int primary key identity(1,1),
Country_name varchar(80)
)
insert into tblcountry (Country_name )values('india')
insert into tblcountry (Country_name )values('nepal')
insert into tblcountry (Country_name )values('bhootan')
insert into tblcountry (Country_name )values('maynmar')
insert into tblcountry (Country_name )values('usa')
insert into tblcountry (Country_name )values('uk')
insert into tblcountry (Country_name )values('japan')
insert into tblcountry (Country_name )values('china')
insert into tblcountry (Country_name )values('alvania')

create table tbloccupation


(id int primary key identity(1,1),
Occupation_name varchar(70))
insert into tbloccupation (Occupation_name )values('business')
insert into tbloccupation (Occupation_name )values('selfemployement')
insert into tbloccupation (Occupation_name )values('Acting')
insert into tbloccupation (Occupation_name )values('Dancing')
insert into tbloccupation (Occupation_name )values('Singing')
insert into tbloccupation (Occupation_name )values('other')
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@
design code
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"


Inherits="newdymicdrpdwn.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table >
<tr>
<td>Name:</td>
<td><asp:TextBox ID ="textname"
runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Gender:</td>
<td><asp:RadioButtonList ID ="rblgender" runat ="server"
RepeatColumns ="3">
<asp:ListItem Text ="male" Value ="1"></asp:ListItem>
<asp:ListItem Text ="female" Value ="2"></asp:ListItem>
<asp:ListItem Text ="other" Value ="3"></asp:ListItem>
</asp:RadioButtonList> </td>
</tr>
<tr>
<td>Country:</td>

<td><asp:DropDownList ID="ddlcountry"
runat="server"></asp:DropDownList></td>
</tr>
<tr>
<td>Occupation:</td>
<td><asp:DropDownList ID ="ddlpesha" runat="server">

</asp:DropDownList></td>
</tr>
<tr>
<td></td>
<td><asp:Button ID ="btninsert" runat="server" Text="Submit"
OnClick="btninsert_Click" /></td>
</tr>
<tr>
<td></td>
<td><asp:GridView ID ="grdvu" runat="server" text="Display"
></asp:GridView> </td>
</tr>
</table>
</div>
</form>
</body>
</html>

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

csharp 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;
namespace newdymicdrpdwn
{
public partial class WebForm1 : System.Web.UI.Page
{

SqlConnection con = new SqlConnection("data source=DESKTOP-AD5CCNP\\


SQLEXPRESS; initial catalog= skk90; integrated security=true");
protected void Page_Load(object sender, EventArgs e)
{

Display();
if (!IsPostBack)
{
DisplayCountry();
DisplayOccupation();
}
}
public void Display()
{
con.Open();
SqlCommand cmd = new SqlCommand("select* from tblinfo", con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
con.Close();
grdvu.DataSource = dt;
grdvu.DataBind();
}
public void DisplayCountry()
{
con.Open();
SqlCommand cmd = new SqlCommand("select* from tblcountry ", con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
con.Close();
ddlcountry.DataValueField = "id"; // table me jiske paas value
123456 hai uska name yha paas krna hota hai// tblcountry ki id paas kri hai
ddlcountry.DataTextField = "Country_name"; // text me jisme data hai
uska name //check in table
ddlcountry .DataSource = dt;
ddlcountry .DataBind();
ddlcountry.Items.Insert(0, new ListItem("--select--", "0"));
}
public void DisplayOccupation()
{
con.Open();
SqlCommand cmd = new SqlCommand("select* from tbloccupation ", con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
con.Close();
ddlpesha.DataValueField = "id";
ddlpesha.DataTextField = "Occupation_name";
ddlpesha.DataSource = dt;
ddlpesha.DataBind();
ddlpesha.Items.Insert(0, new ListItem("--select--", "0"));
}
protected void btninsert_Click(object sender, EventArgs e)
{

con.Open();
SqlCommand cmd = new SqlCommand("insert into
tblinfo(name,gender,country, occupation)values('" + textname .Text +"','"+rblgender
.SelectedValue +"','"+ddlcountry .SelectedValue +"','"+ddlpesha .SelectedValue
+"')", con);
cmd.ExecuteNonQuery();
con.Close();
Display();

}
}
}

También podría gustarte