在数据库中插入多个列表框值 [英] insert multiple list box value in database

查看:82
本文介绍了在数据库中插入多个列表框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在有一个复选框列表,其值为A,B,C,D,现在是文本框中的用户,当我点击保存按钮时,复选框列表的值选择为1,b,c或a,b,d喜欢组合

这个值在每行中分别保存到数据库中,对应用户或在文本框中输入的值



我怎样才能得到当我点击编辑按钮时,该值返回到相应的复选框

I have checkboxlist having values as A , B , C , D now and user in the textbox now when i click on the save button the value of the checkboxlist whichever is selected like 1 , b , c or a , b , d like combination
the value gets saved into database seprately in each row against the user or value entered in the textbox

and how can i get back the value when i click on the edit button the vale gets back to the respective checkbox

<asp:CheckBoxList ID="CheckBoxList1" runat="server"

                        RepeatDirection="Horizontal">
                        <asp:ListItem>Sun</asp:ListItem>
                        <asp:ListItem>Mon</asp:ListItem>
                        <asp:ListItem>Tue</asp:ListItem>
                        <asp:ListItem>Wed</asp:ListItem>
                        <asp:ListItem>Thu</asp:ListItem>
                        <asp:ListItem>Fri</asp:ListItem>
                        <asp:ListItem>Sat</asp:ListItem>
                        <asp:ListItem>Sun</asp:ListItem>
                    </asp:CheckBoxList>

        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Save" onclick="Button1_Click"

              Width="82px" />

推荐答案

Hello Sandeep



您可以实现如下所示的按钮事件处理程序以获取所有选定的项目文本 -



Hello Sandeep

You can implement your button event handler like below to get all selected items Text -

protected void Button1_Click(object sender, EventArgs e)
        {
            List<string> lstItems = new List<string>();
            foreach (ListItem listItem in CheckBoxList1.Items)
            {
                if (listItem.Selected)
                {
                    lstItems.Add(listItem.Text);
                }

            }
        }







//然后你可以实现数据库插入逻辑



谢谢




//then you can implement database insertion logic

Thanks


这篇关于在数据库中插入多个列表框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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