如何在TextBox和CheckBoxList之间建立关系 [英] how to make a relation between TextBox and CheckBoxList
本文介绍了如何在TextBox和CheckBoxList之间建立关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文本框和CheckBoxList
如果我在TextBox中输入orderid(order id是数据库中的列名),那时候想在CheckBox List中显示订单ID的状态
在CheckBoxList中,我有四个项目
翻新,已完成,已验证,已取消
如何显示已点击,例如装修或完成,已验证,已取消的订单编号
请给我一个解决方案
i Have a textbox and CheckBoxList
If i enter orderid in TextBox(order id is the column name in my database) ,that time want to show the status of order id in CheckBox List
In the CheckBoxList i have four items
Renovated,completed,validated,cancelled
how to show clicked ,for example the orderid renovated or completed,validated,cancelled
Please give me a solution
推荐答案
如果您有2table,则第一个用于订单,第二个用于状态,并且每个订单都有一个status_id,这是解决方案:
这应该是您的标记:
if you have 2table , first for orders and second for status, and each order have a status_id, this is the solution:
this should be your markup:
<asp:TextBox ID="TextBox1" runat="server" ontextchanged="TextChanged"></asp:TextBox>
<asp:Repeater ID="rptstatus" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1"
Checked='<%#(int)Eval("status_id")==(int)Session["id"] %>'
Text='<%#Eval("status") %>' runat="server" Enabled="False" />
</ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%
ConnectionStrings:testConnectionString span> =" 选择*来自[状态]" < /asp:SqlDataSource >
ConnectionStrings:testConnectionString %>" SelectCommand="SELECT * FROM [status]"></asp:SqlDataSource>
这是后面的代码:
and this is for code behind:
protected void Page_Load(object sender, EventArgs e)
{
//set session to 0 for first page load and empty text box
if (!Page.IsPostBack)
{
Session["id"] = 0;
}
}
protected void TextChanged(object sender, EventArgs e)
{
int id = Convert.ToInt32(TextBox1.Text);
using (var context = new testEntities())
{
var status_id = (from a in context.orders where a.order_id == id select a).FirstOrDefault();
Session["id"] = status_id.status_id;
//here you get the status id and set it to session
}
}
如有疑问请发表评论!
comment if you have a question!
这篇关于如何在TextBox和CheckBoxList之间建立关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文