Click here to Skip to main content
15,880,725 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
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.NET
<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>


C#
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
   {

       for (int i = 0; i &lt; CheckBoxList1.Items.Count; i++)
       {
           if (CheckBoxList1.Items[i].Selected)
           {
               name += CheckBoxList1.Items[i].Value + &quot;,&quot;;

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

   }
Posted
Updated 31-Jul-15 10:37am
v3
Comments
njammy 30-Jul-15 8:44am    
Please can you give me the value of TextBox1.Text after you click Button2_Click? Hit reply to this comment and let me know.
njammy 30-Jul-15 8:49am    
Also please use the Improve Question option to explain the current problem you are getting; "Unable to store value" could mean lots of different possible problems, please explain.
ZurdoDev 30-Jul-15 10:28am    
Where are you stuck?
Gurpreet Arora Malhotra 3-Aug-15 1:38am    
I retrieve value in textbox 1 .text i want to insert the value in database but i unable to do that
ZurdoDev 3-Aug-15 7:40am    
Where is the code to save it to the database? I don't see any.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900