2
Reply

Problem in bind dropdownlist

dhanu sahu

dhanu sahu

Apr 5 2008 5:59 AM
7k

Hello Friends,

I am using dropdownlist (listitem) for showing months and year,my aim is to according to selection of two dropdown list my data will bind with dataview,it nt showing error but my desired data not retrive,

can you plz suggest me wat i ll do.....

Code:

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Data.SqlClient;

public partial class Er_TimeSheetHistory : System.Web.UI.Page

{

public string strcon1 = "Data Source=LENOVO-EF645A82;AttachDbFilename=E:\\ERSYSTEMS_WEB_1\\DataSourse\\EmpDb1.mdf;Initial Catalog=Erdata;Integrated Security=True";

public string WelcomeName;

SqlDataReader dr;

SqlParameter mparam, yparam;

SqlCommand cmd;

protected void Page_Load(object sender, EventArgs e)

{

WelcomeName = Session["userid"].ToString();

//lbldate.Text = DateTime.Now.ToString ();

DateTime Date = DateTime.Now;

Label2.Text = Date.ToString("MMMM");

Label3.Text = Date.ToString("YYYY");

}

protected void BtnSubmit_Click1(object sender, EventArgs e)

{

//SqlConnection conn = new SqlConnection(strcon );

//SqlCommand cmd = new SqlCommand("select * from D_TimeSheet where Empid="+Session ["usid"]+" AND Month="+lstmonth.SelectedItem .Text.ToString () +" AND Year="+lstyear .SelectedItem .Text +"",conn );

//SqlDataAdapter da = new SqlDataAdapter(cmd );

//DataSet ds = new DataSet();

//da.Fill(ds);

//GridView2.DataSource = ds;

//GridView2.DataBind();

}

protected void Button1_Click(object sender, EventArgs e)

{

SqlConnection conn = new SqlConnection(strcon1);

SqlCommand cmd = new SqlCommand();

cmd.CommandText = "select * from D_TimeSheet where Empid=" + Session["usid"] + " AND ([Month] = @Month) AND ([Year] = @Year) ";

cmd.CommandType = CommandType.Text;

cmd.Connection = conn;

mparam = new SqlParameter(); mparam.ParameterName = "@Month"; mparam.SqlDbType = SqlDbType.VarChar ; mparam.Size = 50; mparam.Direction = ParameterDirection.Input;

mparam.Value = lstmonth.SelectedValue;

yparam = new SqlParameter(); yparam.ParameterName = "@Year"; yparam.SqlDbType = SqlDbType.VarChar; yparam.Size = 50; yparam.Direction = ParameterDirection.Input;

yparam.Value = lstyear.SelectedValue;

cmd.Parameters.Add(mparam);

cmd.Parameters.Add(yparam);

cmd.Connection.Open();

dr = cmd.ExecuteReader(CommandBehavior .CloseConnection );

GridView1.DataSource = dr;

GridView1.DataBind();

}

}

 

 

 


Answers (2)