无法在数据库中存储选定的值 [英] Unable to store selected value in database
本文介绍了无法在数据库中存储选定的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我需要帮助我在asp.net的复选框列表中创建一个复选框列表我显示的名称来自表,我想在不同的表中存储该名称的ID,我不想在文本框中向用户显示值
Hi
I need a help I create a checkbox list in asp.net in checkbox list i show the name from the table and i want to store the Id of that name in different table and I dont want to show the value to user in textbox
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" TextMode="MultiLine" runat="server"></asp:TextBox>
<asp:Panel ID="Panel1" runat="server">
<asp:CheckBoxList ID="CheckBoxList1" OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="Name" DataValueField="Test_Id"></asp:CheckBoxList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Test %>" SelectCommand="SELECT * FROM [test2]"></asp:SqlDataSource>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (CheckBoxList1.Items[i].Selected)
{
name += CheckBoxList1.Items[i].Value + ",";
}
TextBox1.Text = name;
}
}
protected void Button2_Click(object sender, EventArgs e)
{
bool n = false;
string Name = "test";
byte Test_Id = Convert.ToByte(TextBox1.Text);
byte Id = 0;
tt.Order_By_Test1(ref Connection_string, out Id);
Id = Convert.ToByte(Id + 1);
tt.Insert_Test1(ref Connection_string, ref Id, ref Name, ref Test_Id, out n);
}
推荐答案
ConnectionStrings:Test%> SelectCommand = SELECT * FROM [test2] > < / asp:SqlDataSource >
< / asp:Panel >
< / ContentTemplate >
< / asp:UpdatePanel >
ConnectionStrings:Test %>" SelectCommand="SELECT * FROM [test2]"></asp:SqlDataSource> </asp:Panel> </ContentTemplate> </asp:UpdatePanel>
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (CheckBoxList1.Items[i].Selected)
{
name += CheckBoxList1.Items[i].Value + ",";
}
TextBox1.Text = name;
}
}
protected void Button2_Click(object sender, EventArgs e)
{
bool n = false;
string Name = "test";
byte Test_Id = Convert.ToByte(TextBox1.Text);
byte Id = 0;
tt.Order_By_Test1(ref Connection_string, out Id);
Id = Convert.ToByte(Id + 1);
tt.Insert_Test1(ref Connection_string, ref Id, ref Name, ref Test_Id, out n);
}
这篇关于无法在数据库中存储选定的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文