Click here to Skip to main content
15,921,841 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I Have Table Named Items It Has Three Columns Itemname,Price,Category. I Create A Form Having Datagridview&Combobox. I Want When I Select Category In Combobox Then Only Itemname And Price With. in combobox i write all categories which table named items. now i want when i select any category only filtered data related with selected category will be shown in datagridview...
Posted
Updated 20-Feb-14 8:58am
v3
Comments
OriginalGriff 20-Feb-14 3:58am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Try editing your question, set the subject to "DataGridView Problem" and put the body of your question in the actual body.
Then, expand the body so it makes sense to us mere mortals who are trying to work out what the heck you are trying to do, what you have tried, where you are stuck, and what help you need!
Use the "Improve question" widget to edit your question and provide better information.
[no name] 20-Feb-14 8:17am    
Could you please be more specific ?
Krunal Rohit 20-Feb-14 8:23am    
with what?
-KR
agent_kruger 20-Feb-14 8:23am    
sir, kindly write your query downwards and enter the heading were you have written the matter.

Sorry for delaying..

SqlCommand cmd;
string str;
SqlDataReader dr,dr1;

ON ddl_category Click event and set it to Autopost Back True

str = "select itemname,price from items where category=@category";
cmd = new SqlCommand();
cmd.CommandText = str;
cmd.Parameters.AddWithValue("@category",ddlcate.Text.Trim());
cmd.Connection = con;
if (con.State == ConnectionState.Closed)
{
con.Open();
}
dr1 = cmd.ExecuteReader(CommandBehavior.CloseConnection);
if (dr1.HasRows)
{
GridView1.DataSource=dr1;
GridView1.DataBind();
}
 
Share this answer
 
you can fire an event on combobo' selection and re bind your data to gridview according to category selection,

hope it would help you..
 
Share this answer
 
Comments
[no name] 20-Feb-14 8:17am    
I think you assumption is correct :)

Regards,
-PN
Member 10481714 20-Feb-14 14:51pm    
sdap_india sir tell me in detail...
we are not able to get your problem.
please add the entire question in textarea
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900