从按钮检索ID [英] retrieve id from button

查看:70
本文介绍了从按钮检索ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我需要一些帮助或可能需要一些解决方案来解决我的问题.如何从下拉列表中检索ID,当我单击添加"按钮时,添加页面将基于从下拉列表中选择的ID保存数据.例如dropdownlist

hello i need some favor or may some solution to solve my problem. how to retrieve id from dropdownlist and when i click add button, the add page will save the data based on selected id from dropdownlist..? eg dropdownlist

<asp:DropDownList ID="question1" runat="server" SelectedValue='<%#Eval ("q1") %>'>
<asp:ListItem Text="Medium" Value="M" />
<asp:ListItem Text="Easy" Value="A" />
</asp:DropDownList>



当我选择简单"时,添加"按钮将可用于添加并直接响应Add.aspx页并基于简单ID"保存输入的数据..



when i select easy, Add button will available to add and directly response to Add.aspx page and save the entered data based on easy id..?

推荐答案

代码.希望对您有帮助.

Here is the code..Hope it will help you..

string sqlQuery = "Select " + colName + ",0 as " + colValue + " Union Select " + colName + "," + colValue + " from " + tblName;
            if (srchCodn != "")
            {
                sqlQuery += " " + srchCodn;
            }
            adp = new SqlDataAdapter(sqlQuery, conn);
            tbl = new DataTable();
            adp.Fill(tbl);
            ddlList.DataSource = tbl;
            ddlList.DataTextField = colName;
            ddlList.DataValueField = colValue;
            ddlList.DataBind();



绑定ddlList之后,您可以使用ddlList.DataValueField来获取值.



After Binding ddlList you can get the value using ddlList.DataValueField.


这篇关于从按钮检索ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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