<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="empdetailsfromdb.aspx.cs" Inherits="csvfileupload2.empdetailsfromdb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<asp:Label ID="Label2" runat="server" Text="select first_name"></asp:Label>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="search" />
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.Configuration;
using System.Data;
using System.IO;
namespace csvfileupload2
{
public partial class empdetailsfromdb : System.Web.UI.Page
{
string str = "Data Source=ANIRUDDHA-PC;Initial Catalog=sark;Integrated Security=True";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
String strQuery = "SELECT distinct (city) FROM profilesrr";
SqlConnection con = new SqlConnection(str);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = strQuery;
cmd.Connection = con;
try
{
con.Open();
DropDownList1.DataSource = cmd.ExecuteReader();
DropDownList1.DataTextField = "city";
DropDownList1.DataValueField = "city";
DropDownList1.DataBind();
// DropDownList2.SelectedIndex = 1;
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
// con.Dispose();
}
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
String strQuery = "SELECT distinct (first_name) FROM profilesrr";
SqlConnection con = new SqlConnection(str);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = strQuery;
cmd.Connection = con;
try
{
con.Open();
DropDownList2.DataSource = cmd.ExecuteReader();
DropDownList2.DataTextField = "first_name";
DropDownList2.DataValueField = "first_name";
DropDownList2.DataBind();
// DropDownList2.SelectedIndex = 1;
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
con.Dispose();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string str = "Data Source=ANIRUDDHA-PC;Initial Catalog=sark;Integrated Security=True";
SqlConnection con = new SqlConnection(str);
SqlCommand cmd = new SqlCommand("select * from profilesrr where city = '" + DropDownList1.SelectedValue + "' and first_name='" + DropDownList2.SelectedValue + "'", con);
SqlDataAdapter Adpt = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
Adpt.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
//code for DropDownList2_SelectedIndexChanged
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}