dimanche 28 juin 2015

I want to fetch employee information by selecting employee_id from dropdownlist in c#.net

My database has employee id, name, Email, address, and phoneno. I have used a dropdownlist for selection of employee id, for this I wrote this 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;

public partial class Employeedetails : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection("Data Source=REVATI-PC;Initial Catalog=Test_Database;Integrated Security=True");
    SqlCommand cmd;
    SqlDataAdapter da;
    string query;

    protected void Page_Load(object sender, EventArgs e)
    {
        con.Open();
        query = "select Employee_ID from Employee";
        cmd = new SqlCommand(query, con);

        SqlDataReader dr = cmd.ExecuteReader();

        while (dr.Read())
        {
            DropDownList1.Items.Add(dr[0].ToString());
        }

        con.Close();

but by clicking on those particular id, I did not get other information. For this I used SelectIndexchanged event and write a select query

 protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
 {
        string query = "select Employee_ID from Employee where Employee_ID='" + DropDownList1.SelectedValue.ToString() + "'";
        con.Open(); 
}

But it's not working

Aucun commentaire:

Enregistrer un commentaire