Click here to Skip to main content
15,891,942 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a master page in witch more then 30 button like (java,asp,php,sql,c,c++,etc...)
and a have a table of questions. all questions are tagged with one subject like asp,java,etc.


i want to get data according to the click button.
how its possible.

(i think one page for one button is not good idea.)

What I have tried:

C#
protected void BindRepeaterData()
    {
        con.Open();
        SqlCommand cmd = new SqlCommand("SELECT * from question", con);
        int count = (int)cmd.ExecuteScalar();
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(ds);
        RepDetails.DataSource = ds;
        RepDetails.DataBind();
        con.Close();
    }
Posted
Updated 31-Jan-17 1:18am
v2
Comments
CHill60 28-Jan-17 12:15pm    
You will need a WHERE clause in your sql query and use SqlParameter to add the text into the query for which ever button was pressed.
You will also need to ExecuteQuery rather than ExecuteScalar so that you can get all of the results for each topic.
Beyond that I can't help as there is not enough information
ZurdoDev 31-Jan-17 7:05am    
I guess, please post this as a solution.
CHill60 31-Jan-17 7:19am    
Done!
Member 12677198 29-Jan-17 2:36am    
thanks

1 solution

As per my comment above ...

You will need a WHERE clause in your sql query and use SqlParameter to add the text into the query for which ever button was pressed.
You will also need to ExecuteQuery rather than ExecuteScalar so that you can get all of the results for each topic.
Beyond that I can't help as there is not enough information.
It's probably going to be something like this (not tested or compiled) ...
protected void BindRepeaterData(string topic)
    {
        con.Open();
        SqlCommand cmd = new SqlCommand("SELECT * from question WHERE topic=@topic", con);
        cmd.Parameters.AddWithValue("@topic", topic);
        //int count = (int)cmd.ExecuteScalar(); //don't need this at all
        DataSet ds = new DataSet();
        da.Fill(ds);
...
        int count = ds.Tables[0].Rows.Count;
 
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