locked
If condition for Page number in List view in VB.NET RRS feed

  • Question

  • User-1578974752 posted

    I have a list view which have values retrieving from the database and a Save Button inside the List view. Below paging is in the list view.Is it possible to do as below?

    If I click page 1..and Click Save then Save button will become invisible until the user click page 2.After clicking Page 2,then  Save button must be visible.

    In save button click event I can put savebutton.visible=false.But how to set in  such a way that below page number2 when click,the sve button must be visible.

    [This is to avoid double clicking the save button by the user in the same page]

    <asp:Datapager ID="dtpgr" runat="server" pagedcontrolid="ListView1" Pagesize="5">

    <Fields>

    <asp:NumericPagerField ButtonCount="5"

    NumericButtonCssClass="numeric_button"

    CurrentPageLabelCssClass="current_page"

    NextPreviousButtonCssClass="next_button" />

    </Fields>

    </asp:DataPager>

    Friday, October 12, 2018 6:49 AM

Answers

  • User-893317190 posted

    Hi shsu,

    I have used your code to have a try , but I couldn't reproduce your problem. Have you added OnPagePropertiesChanged event to your listview ?What do you write in the event?

    Below is my code.

    <asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="CustomerID"  OnPagePropertiesChanged="ListView1_PagePropertiesChanged">
    
                <ItemTemplate>
    
                    <div>
    
                       <%-- <td align="right">
    
                            <asp:Image ID="Image1" runat="server" ImageUrl="~/fail-small.png" /></td>
    
                        <td align="center">
    
                            <td align="left"><%#DataBinder.Eval(Container.DataItem, "Question") %></td>
    
                            <br />
    
                            <asp:Image runat="server" ID="image" ImageUrl='<%#Eval("Path")%>' />--%>
                    </div>
    
                    <p>
    
                        <tr style="background-color: White;">
    
                            <tr>
                                <td align="left" colspan="3">
                                    <%--<asp:HiddenField ID="QuestionDetailID" runat="server" Value='<%#Eval("QuestDetailID") %>' />--%>
                                </td>
                            </tr>
    
                            <td align="left">
                                <asp:Label ID="Option1" runat="server" Text=' <%# Eval("CustomerID") %>'></asp:Label><asp:RadioButton ID="rad1" GroupName="Group1" runat="server" /></td>
    
                            <td align="left">
                                <asp:Label ID="Option2" runat="server" Text=' <%# Eval("CompanyName") %>'></asp:Label>
                                <asp:RadioButton ID="rad2" GroupName="Group1" runat="server" /></td>
    
                            <td align="left">
                                <asp:Label ID="Option3" runat="server" Text=' <%# Eval("ContactTitle") %>'></asp:Label>
                                <asp:RadioButton ID="rad3" GroupName="Group1" runat="server" /></td>
    
    <%--                        <td align="left">
                                <asp:Label ID="Label1" runat="server" Text=' <%# Eval("Option4") %>'></asp:Label>
                                <asp:RadioButton ID="rad4" GroupName="Group1" runat="server" /></td>--%>
    
    
    
                        </tr>
                </ItemTemplate>
    
            </asp:ListView>
    
          
    
            <br />
    
            <br />
    
            <asp:DataPager ID="dtpgr" runat="server" PagedControlID="ListView1" PageSize="5">
    
                <Fields>
    
                    <asp:NumericPagerField ButtonCount="5"
                        NumericButtonCssClass="numeric_button"
                        CurrentPageLabelCssClass="current_page"
                        NextPreviousButtonCssClass="next_button" />
    
                </Fields>
    
            </asp:DataPager>
    
    
    
            </div>
    
     <asp:Button ID="Button1" runat="server" Text="Save"  BackColor="#3366CC" ForeColor="White" Height="28px" Width="77px" OnClick="Button1_Click" />
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT [CustomerID], [CompanyName], [ContactTitle] FROM [Customers]"></asp:SqlDataSource>
        </form>

    The result.

    Best regards,

    Ackerly Xu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 16, 2018 9:22 AM

All replies

  • User-893317190 posted

    Hi shsu,

    You could use listview's OnPagePropertiesChanged event , the event will trigger after the page index has changed.

    Below is my code.

     <asp:ListView ID="ListView1" runat="server" DataKeyNames="CustomerID" DataSourceID="SqlDataSource1"
               OnPagePropertiesChanged="ListView1_PagePropertiesChanged"
                >
              
                <ItemTemplate>
                    <tr style="">
                        <td>
                            <asp:Label ID="CustomerIDLabel" runat="server" Text='<%# Eval("CustomerID") %>' />
                        </td>
                        <td>
                            <asp:Label ID="CompanyNameLabel" runat="server" Text='<%# Eval("CompanyName") %>' />
                        </td>
                        <td>
                            <asp:Label ID="ContactTitleLabel" runat="server" Text='<%# Eval("ContactTitle") %>' />
                        </td>
                    </tr>
                </ItemTemplate>
                <LayoutTemplate>
                    <table runat="server">
                        <tr runat="server">
                            <td runat="server">
                                <table id="itemPlaceholderContainer" runat="server" border="0" style="">
                                    <tr runat="server" style="">
                                        <th runat="server">CustomerID</th>
                                        <th runat="server">CompanyName</th>
                                        <th runat="server">ContactTitle</th>
                                    </tr>
                                    <tr id="itemPlaceholder" runat="server">
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr runat="server">
                            <td runat="server" style="">
                                <asp:DataPager ID="DataPager1" runat="server">
                                    <Fields>
                                        <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False" />
                                        <asp:NumericPagerField />
                                        <asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False" />
                                    </Fields>
                                </asp:DataPager>
                            </td>
                        </tr>
                        <tr>
                            <td><asp:Button ID="Button1" runat="server" Text="save" OnClick="Button1_Click"  /></td>
                        </tr>
                    </table>
                </LayoutTemplate>
               
            </asp:ListView>
           
            <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT [CustomerID], [CompanyName], [ContactTitle] FROM [Customers]"></asp:SqlDataSource>
        </form>

    Code behind. Here I user list.FindControl("Button1") to find the button , but your button may not be found this way  according to where you put your button in  your listview.

    You should use your own code to find the Button according to your case.

     Protected Sub Button1_Click(sender As Object, e As EventArgs)
            Label1.Text = "please don't double click"
            Dim btn As Button = CType(sender, Button)
            btn.Visible = False
        End Sub
    
        Protected Sub ListView1_PagePropertiesChanged(sender As Object, e As EventArgs)
            Dim list As ListView = ListView1
            Dim btn As Button = CType(list.FindControl("Button1"), Button)
            btn.Visible = True
            Label1.Text = ""
        End Sub

    The result.

    Best regards,

    Ackerly Xu

    Monday, October 15, 2018 3:29 AM
  • User-1578974752 posted

    The button is not inside the list view. It is outside the List view.

    The page numbers is binded with List view. But when I click page 2,it is not going through  button1 .visible = true

    Tuesday, October 16, 2018 6:30 AM
  • User-893317190 posted

    Hi shsu,

    If the button is outside the listview , you could visit the button directly .

    Below is my code behind.Consider the button's id is Button1

     Protected Sub Button1_Click(sender As Object, e As EventArgs)
            Label1.Text = "please don't double click"
            'Dim btn As Button = CType(sender, Button)
            'btn.Visible = False
            Button1.Visible = False
        End Sub
    
        Protected Sub ListView1_PagePropertiesChanged(sender As Object, e As EventArgs)
            'Dim list As ListView = ListView1
            'Dim btn As Button = CType(list.FindControl("Button1"), Button)
            Button1.Visible = True
            Label1.Text = ""
        End Sub

    As  to not going through button1.visible=true, in my case , it is run, could you show how you write your code?

    Best regards,

    Ackerly Xu

    Tuesday, October 16, 2018 6:52 AM
  • User-1578974752 posted

    <asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="QuestDetailID" Visible="False">

    <ItemTemplate>

    <div>

    <td align="right">

    <asp:Image ID="Image1" runat="server" ImageUrl="~/fail-small.png" /></td>

    <td align="center">

    <td align="left"><%#DataBinder.Eval(Container.DataItem, "Question") %></td>

    <br />

    <asp:Image runat="server" id="image" ImageUrl='<%#Eval("Path")%>'/>

    </div>

    <p>

    <tr style="background-color:White;">

    <tr><td align="left" colspan="3"> <asp:HiddenField ID="QuestionDetailID" runat="server" Value='<%#Eval("QuestDetailID") %>' /> </td></tr>

    <td align="left"> <asp:Label ID="Option1" runat="server" Text=' <%# Eval("Option1") %>'></asp:Label><asp:RadioButton ID="rad1" GroupName="Group1" runat="server" /></td>

    <td align="left"> <asp:Label ID="Option2" runat="server" Text=' <%# Eval("Option2") %>'></asp:Label> <asp:RadioButton ID="rad2" GroupName="Group1" runat="server" /></td>

    <td align="left"> <asp:Label ID="Option3" runat="server" Text=' <%# Eval("Option3") %>'></asp:Label> <asp:RadioButton ID="rad3" GroupName="Group1" runat="server" /></td>

    <td align="left"> <asp:Label ID="Label1" runat="server" Text=' <%# Eval("Option4") %>'></asp:Label> <asp:RadioButton ID="rad4" GroupName="Group1" runat="server" /></td>

     

    </tr>

    </ItemTemplate>

    </asp:ListView>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:QSCTestConnectionString %>" SelectCommand="SELECT TOP 15 [Question],[Name],[Path],[CorrectAnswer],[Option1], [Option2], [Option3], [Option4], [Option5], [QuestDetailID], [QuestionMasterID] FROM [QuestionDetail] WHERE ([QuestionMasterID] = @QuestionMasterID) ORDER BY NEWID()">

    <SelectParameters>

    <asp:ControlParameter ControlID="qusetid" Name="QuestionMasterID" PropertyName="Text" Type="Int64" />

    </SelectParameters>

    </asp:SqlDataSource>

    <br />

    <br />

    <asp:Datapager ID="dtpgr" runat="server" pagedcontrolid="ListView1" Pagesize="5">

    <Fields>

    <asp:NumericPagerField ButtonCount="5"

    NumericButtonCssClass="numeric_button"

    CurrentPageLabelCssClass="current_page"

    NextPreviousButtonCssClass="next_button" />

    </Fields>

    </asp:DataPager>

     

    </div>

     <asp:Button ID="Button1" runat="server" Text="Save" Visible="false" BackColor="#3366CC" ForeColor="White" Height="28px" Width="77px" />

    Tuesday, October 16, 2018 7:06 AM
  • User-893317190 posted

    Hi shsu,

    I have used your code to have a try , but I couldn't reproduce your problem. Have you added OnPagePropertiesChanged event to your listview ?What do you write in the event?

    Below is my code.

    <asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="CustomerID"  OnPagePropertiesChanged="ListView1_PagePropertiesChanged">
    
                <ItemTemplate>
    
                    <div>
    
                       <%-- <td align="right">
    
                            <asp:Image ID="Image1" runat="server" ImageUrl="~/fail-small.png" /></td>
    
                        <td align="center">
    
                            <td align="left"><%#DataBinder.Eval(Container.DataItem, "Question") %></td>
    
                            <br />
    
                            <asp:Image runat="server" ID="image" ImageUrl='<%#Eval("Path")%>' />--%>
                    </div>
    
                    <p>
    
                        <tr style="background-color: White;">
    
                            <tr>
                                <td align="left" colspan="3">
                                    <%--<asp:HiddenField ID="QuestionDetailID" runat="server" Value='<%#Eval("QuestDetailID") %>' />--%>
                                </td>
                            </tr>
    
                            <td align="left">
                                <asp:Label ID="Option1" runat="server" Text=' <%# Eval("CustomerID") %>'></asp:Label><asp:RadioButton ID="rad1" GroupName="Group1" runat="server" /></td>
    
                            <td align="left">
                                <asp:Label ID="Option2" runat="server" Text=' <%# Eval("CompanyName") %>'></asp:Label>
                                <asp:RadioButton ID="rad2" GroupName="Group1" runat="server" /></td>
    
                            <td align="left">
                                <asp:Label ID="Option3" runat="server" Text=' <%# Eval("ContactTitle") %>'></asp:Label>
                                <asp:RadioButton ID="rad3" GroupName="Group1" runat="server" /></td>
    
    <%--                        <td align="left">
                                <asp:Label ID="Label1" runat="server" Text=' <%# Eval("Option4") %>'></asp:Label>
                                <asp:RadioButton ID="rad4" GroupName="Group1" runat="server" /></td>--%>
    
    
    
                        </tr>
                </ItemTemplate>
    
            </asp:ListView>
    
          
    
            <br />
    
            <br />
    
            <asp:DataPager ID="dtpgr" runat="server" PagedControlID="ListView1" PageSize="5">
    
                <Fields>
    
                    <asp:NumericPagerField ButtonCount="5"
                        NumericButtonCssClass="numeric_button"
                        CurrentPageLabelCssClass="current_page"
                        NextPreviousButtonCssClass="next_button" />
    
                </Fields>
    
            </asp:DataPager>
    
    
    
            </div>
    
     <asp:Button ID="Button1" runat="server" Text="Save"  BackColor="#3366CC" ForeColor="White" Height="28px" Width="77px" OnClick="Button1_Click" />
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT [CustomerID], [CompanyName], [ContactTitle] FROM [Customers]"></asp:SqlDataSource>
        </form>

    The result.

    Best regards,

    Ackerly Xu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 16, 2018 9:22 AM