获取提交按钮ID以进行查询 [英] Get submit button id for query

查看:197
本文介绍了获取提交按钮ID以进行查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个超过30个按钮的母版页面(java,asp,php,sql,c,c ++等等)

和一个问题表。所有问题都标记为一个主题,如asp,java等。





我想根据点击按钮获取数据。

怎么可能。



(我认为一个按钮的一页不是个主意。)



我的尝试:



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:

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();
    }

推荐答案

根据我上面的评论...



你的sql查询中需要一个 WHERE 子句,并使用SqlParameter将文本添加到按下按钮的查询中。

您还需要ExecuteQuery而不是ExecuteScalar,这样您就可以获得每个主题的所有结果。

除此之外我没有帮助,因为没有足够的信息。

它可能会是这样的(未经过测试或编译)...

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;


这篇关于获取提交按钮ID以进行查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆