如何在Dropdown和Gridview1和2中获取数据 [英] How Do I Get Data In Dropdown And Gridview1 And 2

查看:66
本文介绍了如何在Dropdown和Gridview1和2中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

namespace inactive_web
{
    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(CS))
                using (SqlCommand cmd = new SqlCommand("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"))
                {
                    try
                    {
                        con.Open();
                        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.DataBind();
                            DDL1.DataValueField = "EMP_NAME";
                            DDL1.DataTextField = "designation";
                            DDL1.DataBind();
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                    }
                    finally
                    {
                        con.Close();
                    }
                }
            }
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {

            string CS = ConfigurationManager.ConnectionStrings["hodconstr"].ConnectionString;
            using (SqlConnection con = new SqlConnection(CS))
            using (SqlCommand cmd = new SqlCommand("Select HOD,emp_email,EMP_NAME, EMP_CODE, EMP_DEPT, DEPARTMENT, DESIGNATIO from EMPLOYEE WHERE EMP_NAME = '" + DDL1.SelectedValue.ToString() + "' "))
            {
                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();
                    GV2_GV2FUNCTION(DDL1.SelectedValue);
                }
            }
        }

        private void GV2_GV2FUNCTION(string p)
        {
            throw new NotImplementedException();
        }
        protected void GV2FUNCTION(String S)
        {

            string CS = ConfigurationManager.ConnectionStrings["hodconstr"].ConnectionString;
            using (SqlConnection con = new SqlConnection(CS))
            using (SqlCommand cmd = new SqlCommand("Select Emp_code, EmpName = (select emp_name from employee where emp_code = x.emp_code) from car_approver x where hod = '" + S.ToString() + "' "))
            {
                cmd.CommandType = CommandType.Text;
                cmd.Connection = con;
                using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
                {
                    DataSet ds = new DataSet();
                    sda.Fill(ds);
                    GV2.DataSource = ds.Tables[0];
                    GV2.DataBind();
                }
            }

        }















gridview1中有两个表员工和汽车批发商我想要数据无效的hod和in gridview2我希望所有在该特定员工下工作的会员



请告诉我我做错了什么








there are two tables employee and car-aprover in gridview1 i want dataof inactive hod and in gridview2 i want all members who are working under that particular employee

please tell me what did i do wrong

推荐答案





在这里你试着调用GV2_GV2FUNCTION(DDL1.SelectedValue);绑定GV1后的方法。相反,你可以调用GV2FUNCTION(DDL1.SelectedValue);。



希望这能解决你的问题。



谢谢,

Sisir patro
Hi,

Here you are tryinbg to call "GV2_GV2FUNCTION(DDL1.SelectedValue);" method after binding the GV1. Instead you can call the "GV2FUNCTION(DDL1.SelectedValue);".

Hope this will resolve your issue.

Thanks,
Sisir patro


这篇关于如何在Dropdown和Gridview1和2中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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