Home > Blockchain >  How can my GridView Refresh using two Textbox and a Button Using VB ,Asp and ORACLE
How can my GridView Refresh using two Textbox and a Button Using VB ,Asp and ORACLE

Time:10-07

I've been trying to refresh a GridView when two textbox set me the range then click Search, and returns me the columns in that range.

But the thing is, in first load the GridView fills up with all the columns, that works fine but when I click search button doesn't refresh at all, it just stays the same.

                        <asp:UpdatePanel runat="server" UpdateMode="Conditional">
                        <ContentTemplate>
                            <asp:GridView CssClass="table" AllowSorting="true" HeaderStyle-HorizontalAlign="Center" EmptyDataText="No hay pendientes." CellPadding="10" HeaderStyle-CssClass="bg-primary p-2 text-dark bg-opacity-25" runat="server" ID="gvBitacora" AutoGenerateColumns="false">
                                <Columns>
                                    <asp:BoundField DataField="cvebitacora" HeaderText="No" ItemStyle-Font-Bold="true" ItemStyle-Width="3%" ItemStyle-HorizontalAlign="Center" />
                                    <asp:TemplateField HeaderText="Formulario No." ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Center">
                                        <ItemTemplate>
                                            <%# String.Format("{0}-{1}", Eval("cveano"), Eval("cvenumero"))%>
                                        </ItemTemplate>
                                    </asp:TemplateField>

                                    <asp:BoundField DataField="cveusuario" HeaderText="Usuario" ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Center" />
                                    <asp:BoundField DataField="cveestado" HeaderText="Estado" ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Center" />
                                    <asp:BoundField DataField="observacion" HeaderText="Observación" ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Center" />
                                    <asp:BoundField DataField="fechaaccion" HeaderText="Fecha" DataFormatString="{0:dd/ MM/ yyyy}" ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Center" />
                                    <asp:TemplateField HeaderText="Revisión" ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Center">
                                        <ItemTemplate>
                                            <asp:LinkButton ID="btnVer" CssClass="btn btn-primary" runat="server" CommandName="btnVer" CommandArgument="<%# Container.DataItemIndex %>">Ver <i class='far fa-eye'></i></asp:LinkButton>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                </Columns>
                            </asp:GridView>
                        </ContentTemplate>
                    </asp:UpdatePanel>

And here the Button Click in VB

    Private Sub btnBuscar_Click(sender As Object, e As EventArgs) Handles btnBuscar.Click
    Dim user As User = CType(Session.Item("user"), User)
    Dim oBLBitacora As New BLBitacora
    Dim lBitacora, lBitacora2 As New List(Of Bitacora)
    If user.cverol = 2 Then
        If panelsStayOpen_headingOne.Checked = True Then
            lBitacora = oBLBitacora.BitacorasGetDate(dateFechaInicio.Text, dateFechaFinal.Text)
            gvBitacora.DataSource = lBitacora
            gvBitacora.DataBind()
        End If

    ElseIf user.cverol = 3 Then
        lBitacora = oBLBitacora.BitacorasGet(2)
        gvBitacora.DataSource = lBitacora
        gvBitacora.DataBind()
    End If
    End Sub

GridView on first load

PAGE LOAD

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim user As User = CType(Session.Item("user"), User)
    Dim oBLBitacora As New BLBitacora
    Dim lBitacora, lBitacora2 As New List(Of Bitacora)

    If Not IsPostBack Then
        If user.cverol = 2 Then
            lBitacora = oBLBitacora.BitacorasGet(1)
            gvBitacora.DataSource = lBitacora
            gvBitacora.DataBind()
        ElseIf user.cverol = 3 Then
            lBitacora = oBLBitacora.BitacorasGet(2)
            gvBitacora.DataSource = lBitacora
            gvBitacora.DataBind()
        End If
    Else
        If panelsStayOpen_headingOne.Checked = True Then
            panelsStayOpen_headingOne.Attributes("class") = "form-check-input"
            panelsStayOpen_headingOne.Attributes("aria-expanded") = "true"
            panelsStayOpen_collapseOne.Attributes("class") = "accordion-collapse collapse show"
        Else
            panelsStayOpen_headingOne.Attributes("class") = "collapsed form-check-input"
            panelsStayOpen_headingOne.Attributes("aria-expanded") = "false"
            panelsStayOpen_collapseOne.Attributes("class") = "accordion-collapse collapse"
        End If
    End If

CodePudding user response:

where is your page load event showing the initial bind? You'll also want to be sure you call Updatepanel.Update() after the search click.

CodePudding user response:

I've managed to fix it ,the Panel Update needed to be in the initial Form, not only the GridView.

  • Related