如何为我在下拉列表中选择的实体填充我的Gridview [英] How Can I Populate My Gridview For The Entity I Select In Dropdownlist

查看:75
本文介绍了如何为我在下拉列表中选择的实体填充我的Gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在pageload事件中填充的下拉列表。

现在我想要的是,只要我在下拉列表中选择那些人的名字,其所有信息和在他下面工作的人都应该填入datagridview1和datagridview2分别

请建议我对这个技术不熟悉





这是代码:







公共部分类WebForm1:System.Web.UI.Page

{

protected void Page_Load(object sender,EventArgs e)

{

if(!this.IsPostBack)

{

string CS = ConfigurationManager.ConnectionStrings [hodconstr]。ConnectionString;

using(SqlConnection con = new SqlConnection(hodconstr))

使用(SqlCommand cmd = new SqlCommand(从EMPLOYEE中选择*,其中DESIGNATIO ='hod'和ACTIVE ='N'))

{

cmd.CommandType = CommandType.Text;

cmd.Connection = con;

using(SqlDataAdapter sda = new SqlDataAdapter(cmd))

{

DataSet ds = new DataSet();

sda.Fill(ds);

DDL1。 DataSource = ds.Tables [0];

DDL1.DataTextField =Name;

DDL1.DataValueField =CustomerId;

DDL1 .DataBind();

}

}

} DDL1.Items.Insert(0,new ListItem( - 选择不活动的HOD' - - ,0));

}



protected void DropDownList1_SelectedIndexChanged(object sender,EventArgs e)

$


string CS = ConfigurationManager.ConnectionSt rings [hodconstr] .ConnectionString;

using(SqlConnection con = new SqlConnection(hodconstr))

using(SqlCommand cmd = new SqlCommand(Select EMP_NAME, EMP_CODE,EMP_DEPT,DEPARTMENT,DESIGNATIO,EMPLOYEE WHERE))

{

cmd.CommandType = CommandType.Text;

cmd.Connection = con;

使用(SqlDataAdapter sda = new SqlDataAdapter(cmd))

{

DataSet ds = new DataSet();

sda.Fill(ds);

GV1.DataSource = ds.Tables [0];

GV1.DataBind();

}





}

}

}

}

i have a dropdownlist that gets populated on pageload event.
now i want that as soon as i select that persons name in dropdown its all information and person working under him should populate in datagridview1 and datagridview2 respectively
please suggest i ma new to this tecnology


Here is the code:



public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string CS = ConfigurationManager.ConnectionStrings["hodconstr"].ConnectionString;
using (SqlConnection con = new SqlConnection("hodconstr"))
using (SqlCommand cmd = new SqlCommand("Select * from EMPLOYEE where DESIGNATIO = 'hod' AND ACTIVE = 'N'"))
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
DataSet ds = new DataSet();
sda.Fill(ds);
DDL1.DataSource = ds.Tables[0];
DDL1.DataTextField = "Name";
DDL1.DataValueField = "CustomerId";
DDL1.DataBind();
}
}
} DDL1.Items.Insert(0, new ListItem("--Select Inactive HOD'S--", "0"));
}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{

string CS = ConfigurationManager.ConnectionStrings["hodconstr"].ConnectionString;
using (SqlConnection con = new SqlConnection("hodconstr"))
using (SqlCommand cmd = new SqlCommand("Select EMP_NAME, EMP_CODE, EMP_DEPT, DEPARTMENT, DESIGNATIO from EMPLOYEE WHERE "))
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
DataSet ds = new DataSet();
sda.Fill(ds);
GV1.DataSource = ds.Tables[0];
GV1.DataBind();
}


}
}
}
}

推荐答案

下拉列表中所选人员的所有信息都应出现在gridview1和peo中在gridview2下在他下面工作



i是否能够找出哪个声明,因为它取决于下拉列表的选择



------------------------------------------------ ---------------------------------------



#1

选择上限(登录)HODLogin,

上限(Emp_Name)EmpName,

设计名称,
上(部门)部门,

员工分部

登录

(从car_approver中选择不同的hod

其中HOD in(从员工中选择登录,其中active ='N'且emp_name不在(从员工中选择emp_name = active ='Y'))

和hod<> '')订购2



< drop down =>非活动HODS



无效HOD详细信息



HOD登录HOD名称HOD指定HOD部门HOD部门
PRASADS PRASAD SANYAL编辑 - 新闻,NDTV融合内容:英文新闻内容:英文新闻



PRASADS - 以下员工的车辆审批人 -



Emp Code Emp Name

OG3138 Ajit Chandrakant Potle

OL2480 Antriksha Kumar Bhaskar

OP019 Dilip Kumar

OG1728 Gangamurali G Amballa

PA413 Indranil Sen

PA233 Jayant John

PA1592 Rajani

PA3702 Raman Kumar

TC6119 Ruchika Sawhney

OG194 Sanjeev Kumar

OG6497 SHEIKH JANESHAR AKHTER

OGO55 Subhash Chander

OG060 Sushil Kumar

OG6092 Vikas Gour

OG2173 Vinish Kumar

OD048 Zakir Hussain



#2

选择Emp_code,EmpName =(从员工中选择emp_name)来自car_approver x的re emp_code = x.emp_code)其中hod ='PRASADS'

订购2



选择Emp_code,EmpName =(选择来自员工的emp_name,其中emp_code = x.emp_code)来自car_approver x其中hod ='VANDANAP'

订购2





凭证:

服务器:DEL-INTRASQL

数据库名称:test

用户名/密码:testu / test



•第一个查询可以为您提供多个记录

•第二个查询=登录属性应该取第一个查询返回的值

•下拉第一个查询
all info of selected person in dropdownlist should appear in gridview1 and people working under him in gridview2

i was nopt able to figureout where statement because it depends on selection of dropdownlist

---------------------------------------------------------------------------------------

#1
Select upper(login) HODLogin,
Upper(Emp_Name) EmpName,
Designatio designation,
Upper(department) dept,
Division from employee
where login in
(select distinct hod from car_approver
where HOD in (Select login from employee where active = 'N' and emp_name not in (Select emp_name from employee where active ='Y'))
and hod <>'' ) Order by 2

<drop down=""> Inactive HODS

Inactive HOD Details

HOD Login HOD Name HOD Designation HOD Department HOD Division
PRASADS PRASAD SANYAL Editor - News, NDTV Convergence CONTENT : ENGLISH NEWS Content : English News

PRASADS – Vehicle approver of following employees –

Emp Code Emp Name
OG3138 Ajit Chandrakant Potle
OL2480 Antriksha Kumar Bhaskar
OP019 Dilip Kumar
OG1728 Gangamurali G Amballa
PA413 Indranil Sen
PA233 Jayant John
PA1592 Rajani
PA3702 Raman Kumar
TC6119 Ruchika Sawhney
OG194 Sanjeev Kumar
OG6497 SHEIKH JANESHAR AKHTER
OGO55 Subhash Chander
OG060 Sushil Kumar
OG6092 Vikas Gour
OG2173 Vinish Kumar
OD048 Zakir Hussain

#2
Select Emp_code, EmpName = (select emp_name from employee where emp_code = x.emp_code) from car_approver x where hod = 'PRASADS'
Order by 2

Select Emp_code, EmpName = (select emp_name from employee where emp_code = x.emp_code) from car_approver x where hod = 'VANDANAP'
Order by 2


Credentials:
Server : DEL-INTRASQL
Database Name: test
User/password: testu/test

• 1st query can give you multiple records
• 2nd query = login attribute should take values returned by 1st query
• Drop down for first query


这篇关于如何为我在下拉列表中选择的实体填充我的Gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆