小白请教下如何获取当取数据库值aid.
数据库里对应的值是
那现在我怎么获得这个表中的aid出来,我要将这个aid“214”的值写入另一个表中。
要实现用户输入后,知道他所输入值对应的物品,好在另一页面返回出来..
我想的是在页面做个隐藏控件,
如<input type="hidden" runat="server" id="hd_propertyID" />
但不知道后台怎么写,来获得当前选择物品的id,麻烦大神帮小弟解决下。
[解决办法]
定义变量,取得页面中DropDownList的选择项,作为参数传给SQL语句,
下边这个例子只是为了检查要执行的SQL语句是否正确。
当选择cd光盘时,
SQL语句为:select aid from Mytable where class1='光盘' and class2='刻录光盘' and class3='CD光盘'
当选择DVD光盘时,SQL语句为:select aid from Mytable where class1='光盘' and class2='刻录光盘' and class3='DVD光盘'
将SQL语句执行,就能得到你的aid了。
//假设你的页面form中是这样的
<asp:DropDownList ID="ddlFirst" runat="server">
<asp:ListItem>光盘</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlSecond" runat="server">
<asp:ListItem>刻录光盘</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlThird" runat="server">
<asp:ListItem>CD光盘</asp:ListItem>
<asp:ListItem>DVD光盘</asp:ListItem>
</asp:DropDownList>
<br />
<asp:Button ID="btnOk" runat="server" Text="确定" OnClick="btnOk_Click" />
<asp:Label ID="lblTips" runat="server" Text=""></asp:Label>
//后台cs是这样的
protected void btnOk_Click(object sender, EventArgs e)
{
string clsFirst = string.Empty;
string clsSecond = string.Empty;
string clsThird = string.Empty;
string sql = string.Empty;
clsFirst = ddlFirst.SelectedValue;
clsSecond = ddlSecond.SelectedValue;
clsThird = ddlThird.SelectedValue;
sql = "select aid from Mytable ";
sql += " where ";
sql += " class1='" + clsFirst + "' ";
sql += " and class2='" + clsSecond + "' ";
sql += " and class3='" + clsThird + "' ";
lblTips.Text = sql;
}