TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
shally gupta
NA
15
0
gridview filteration
Feb 2 2011 12:02 AM
Hi, I have a problem in filtering gridview based on combo box. I have two seperate controls on form i.e. combo box and gridview. I want when i select some value from combo box, grid view should display only those records. My code is
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindData();
}
}
private void BindData()
{
SqlConnection con = new SqlConnection("Data Source=MANISH;Initial Catalog=AdventureWorks;Integrated Security=True");
SqlDataAdapter dp = new SqlDataAdapter("Select * from emp2", con);
DataSet ds = new DataSet();
dp.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
// combobox_ID =Name
protected void combobox_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=MANISH;Initial Catalog=AdventureWorks;Integrated Security=True");
con.Open();
string empname;
empname = name.SelectedItem.Text;
//empname = TextBox1.Text;
string query = "select * from emp2 where ename=@ename";
SqlCommand cmd = new SqlCommand(query, con);
cmd.Parameters.Add(new SqlParameter("@ename", empname));
cmd.ExecuteNonQuery();
con.Close();
//GridView1.DataBind();
BindData();
Lbtext.Text = "query executed";
}
can u plz help.
Reply
Answers (
16
)
Universal Code to Insert in Virtual Web Ripper to Extract Large Images
rtf tag