动态绑定网格视图

本文关键字:视图 网格 动态绑定 | 更新日期: 2023-09-27 17:59:32

我已经在页面加载时绑定了我的网格视图,但我希望在用户向下滚动时绑定数据。

我已经使用存储过程绑定了gridview

当用户每10行向下滚动时,如何在网格中动态绑定行?

<asp:GridView ID="GridViewUserSkillQuery" runat="server" AutoPostBack="True" AutoGenerateColumns="false" Width="100%" RowStyle-ForeColor="Black" GridLines="None" OnDataBound="GridViewUserSkillQuery_DataBound">
    <RowStyle ForeColor="Black"></RowStyle>
      <Columns>
          <asp:TemplateField>
            <ItemTemplate>
                  <div class="box">
                       <div class="image">
                            <asp:Image ID="imguser" runat="server" Width="60px" Height="60px" CssClass="user_image" AlternateText="image not found"                                                        ImageUrl='<%# Bind("Image") %>' />
                             <div class="user_profession"> 
                                <asp:Label ID="lblProfession" Font-Size="10px" ForeColor="#752F8E" runat="server"                                                  Text="student"></asp:Label>
                                                   <%-- Text='<%# Bind("Profession") %>'--%>  </div>
                              </div>
                              <div class="box2">
                                  <div class="name">
                                     <asp:LinkButton ID="lbtnUsername" Font-Overline="false" runat="server" Text='<%# Bind("Name") %>'                                                             ForeColor="#752F8E" OnClick="lbtnUsername_Click"></asp:LinkButton>
                                     <asp:Label ID="lblQuser" runat="server" Text='<%# Bind("Uid") %>' Visible="false"></asp:Label>
                                   </div>
                                   <div class="category">  related to:
                                     <asp:Label ID="lblskillname" runat="server" Text='<%# Bind("SkillName") %>' ForeColor="#752F8E"></asp:Label>
                                   </div>
                                   <div class="time">
                                                    (
                                     <asp:Label ID="lblDatetime" runat="server" Font-Size="12px" Text='<%# Bind("EntryDate") %>'></asp:Label>
                                                    )
                                  </div>
                                  <div class="count">
                                        <asp:Label ID="lblanscount" runat="server" Text='<%# Bind("AnsCount") %>' ForeColor="#752F8E"></asp:Label><br />
                                                    Answer
                                  </div>
                              </div>
                              <div class="box3">
                                     <div class="title">
                                                    QTitle:
                                                    <asp:LinkButton ID="lbltitle" runat="server" Text='<%# Bind("Title") %>' OnClick="lbltitle_click"
                                                        ForeColor="Gray"></asp:LinkButton>
                                                </div>
                                                <div class="query">
                                                  <div class="q">Q:</div>
                                                    <asp:Label ID="lblQuery" runat="server" Text='<%# Bind("Query") %>'></asp:Label>
                                                    <asp:Label ID="lblQueryID" runat="server" Text='<%# Bind("QueryID") %>' Visible="false"></asp:Label>
                                                </div>
                                 </div>
                                 <div class="box4">
                                                <div class="reply">
                                                    <asp:Button ID="btnAnswer" runat="server" Text="Answer the Query" OnClick="lbltitle_click"
                                                         CssClass="in_button" ForeColor="White" />
                                                </div>
                                            </div>
                                  </div>
              </ItemTemplate>
            </asp:TemplateField>
     </Columns>
   </asp:GridView>

动态绑定网格视图

您可以使用AJAX来实现这一点。其中最困难的部分是下面收集的行的EDIT和DELETE函数。

详细的教程可以在这里找到。