<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="_2905json_passing.WebForm1" %>
Bind Dropdownlist json
aspx.cs code
 
 
 
 
 
 
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Web.Services;
using Newtonsoft.Json;
using System.Web.Script.Serialization;
namespace _2905json_passing
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var data = BindDropdownlist();
DropDownList1.DataSource = data;
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, "Select name");
}
public static string[] BindDropdownlist()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter("Select Name from Customers", con);
da.Fill(dt);
return dt.AsEnumerable().Select(k => k[0] + "").ToArray();
}
public static string Getdata(string Names)
{
if(BindDropdownlist().Contains(Names))
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
SqlCommand cmd =new SqlCommand("select * from Customers" + Names ,con);
SqlDataAdapter da=new SqlDataAdapter(cmd);
DataTable dt=new DataTable();
da.Fill(dt);
string jsdata=JsonConvert.SerializeObject(dt);
return jsdata;
}
else
return "Names are not showing";
}
}
}
 
 
in that above based on the dropdown selection that value move to the text box