试图找到一种将项目动态添加到复选框的方法

问题描述 投票:0回答:1

我有一个复选框列表,我在其中填充了数据库表中的值。我已经添加了用户可以通过模式弹出窗口将项目添加到复选框列表中的功能:

<section class="submodal submodalWindow" id="popupFour" style="margin-top: -142px; height: 388px; width: 400px; border: solid; margin-left: -627px; top: 42%; left: 68%">
                <section class="submodalWrapper" style="height: 342px">
                    <h1 class="h3 mb-0 text-gray-800">Add a Document</h1>

                    <hr />

                    <div class="card pmd-card">
                        <div class="card-body">
                            <!-- Basic Information -->
                            <div class="details-tab">

                                    <div style="margin-bottom:10px">
                                        <label class="pmd-list-subtitle">Document</label>
                                        <asp:TextBox class="form-control" runat="server" ID="tbDocument"></asp:TextBox>                                        
                                    </div>

                                <asp:UpdatePanel runat="server" ID="UpdatePanel33">
                                    <ContentTemplate>
                                        <asp:LinkButton runat="server" ID="btnPacketAdd" OnClick="btnPacketAdd_Click" class="d-none d-sm-block btn btn-sm btn-success shadow-sm"><i class="fas fa-plus-circle fa-sm text-white-50" style="padding-right:10px"></i>Add</asp:LinkButton>
                                    </ContentTemplate>
                                </asp:UpdatePanel>

                            </div>

                                <asp:LinkButton ID="LinkButton6" runat="server" class="d-none d-sm-inline-block btn btn-lg btn-success shadow-sm modalButton" Style="margin-left:95px; margin-top:20px"><i class="fas fa-backward fa-sm text-white-50"></i>Back</asp:LinkButton>
                        </div>
                    </div>
                </section>
                <a class="subcloseBtn">CLOSE X</a>
            </section>

我的问题是,当我尝试通过模式弹出窗口添加新项目时,它不会立即更新复选框列表。我将不得不关闭该应用程序并再次运行它,以使新添加的项目出现。我已经根据网上的一些帖子设置了AutoPostBack=True,但是,这可能是我第一次在此遗漏了一些信息。下面的代码是如何将项目存储到表中:

Protected Sub btnPacketAdd_Click(sender As Object, e As EventArgs) Handles btnPacketAdd.Click
        Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings("HRRecruitmentDBConn").ToString())
            ' Create a command object.
            Dim cmd As New SqlCommand()

            ' Assign the connection to the command.
            cmd.Connection = conn

            cmd.CommandText = "INSERT INTO tblCredentialingPacket (Packet_Item, Status) VALUES (@Packet_Item, @Status)"

            cmd.CommandType = CommandType.Text

            cmd.Parameters.AddWithValue("@Status", 1)
            cmd.Parameters.Add("@Packet_Item", SqlDbType.NVarChar, 150).Value = tbDocument.Text

            conn.Open()

            cmd.Connection = conn



            cmd.ExecuteNonQuery()

        End Using

    End Sub

asp.net vb.net checkboxlist
1个回答
0
投票

我知道了。我创建了一个名为BindCheckBoxList()的函数,该函数将数据源绑定到我的复选框列表,因此,每当我从模式弹出窗口中添加新项目时,它都会自动更新复选框列表。

© www.soinside.com 2019 - 2024. All rights reserved.