我的Gridview在Asp.net更新面板中没有绑定

时间:2016-07-21 18:59:32

标签: asp.net gridview updatepanel

我有一个Gridview控件,我用来绑定3个不同的数据表从数据库工作正常没有UpdatePanel但是当它来到更新面板时它只工作一次,当我点击任何按钮,再次,如果我点击另一个按钮button_Click执行事件,但我的Gridview没有显示新数据,只显示旧记录 我也使用此行代码UpdatePanel1.Update()没有用 这是我的代码

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>    
   <ul class="nav nav-tabs">
    <li id="licommentAll" class="active" runat="server">
        <asp:LinkButton ID="lnkCommentALL" runat="server" OnClick="lnkCommentALL_Click">
            All
        </asp:LinkButton>
    </li>
    <li id="licommentApproval" runat="server">
        <asp:LinkButton ID="lnkCommentApproval" runat="server" OnClick="lnkCommentApproval_Click">
            Approval
        </asp:LinkButton>
    </li>
    <li id="licommentPending" runat="server">       
        <asp:LinkButton ID="lnkCommentPending" runat="server" OnClick="lnkCommentPending_Click">
            Pending <asp:Label ID="lblPendingCount" CssClass="badge" runat="server"></asp:Label>
        </asp:LinkButton>
    </li>
       <li id="licommentSpam" runat="server">
        <asp:LinkButton ID="lnkCommentSpam" runat="server" OnClick="lnkCommentSpam_Click">
            Spam
        </asp:LinkButton>
    </li>
  </ul>
     <div class="tab-content">
    <div role="tabpanel" id="divCommentSubMenu" style="width:100%;">
        <asp:GridView ID="GridComment" runat="server" AutoGenerateColumns="false">
            <Columns>
                <asp:TemplateField>
                    <HeaderTemplate>
                        <div class="row" style="padding:20px;">
                            <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
                                <asp:CheckBox ID="chkParent" runat="server" />&nbsp;&nbsp;
                                <div class="btn-group btn-group-xs" role="group" aria-label="...">
                                    <asp:Button ID="btnApprove" runat="server" CssClass="btn btn-primary" Text="Approve" OnClick="btnApprove_Click" />
                                    <asp:Button ID="btnSpam" runat="server" CssClass="btn btn-primary" Text="Spam" OnClick="btnSpam_Click" />
                                    <asp:Button ID="btnDelete" runat="server" CssClass="btn btn-primary" Text="Delete" OnClick="btnDelete_Click" />
                                </div>                                
                             </div>
                            <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
                            <div class="dropdown" style="margin-top:10px; float:right;">
                               <button class="btn btn-default dropdown-toggle btn-xs" type="button" id="dropdownMenucommentdate" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
                                Search Comment
                                <span class="caret"></span>
                               </button>
                               <ul class="dropdown-menu" aria-labelledby="dropdownMenucommentdate">
                                <li>
                                    <asp:LinkButton ID="lnkToday" runat="server">Today</asp:LinkButton>
                                </li>
                                <li>
                                    <asp:LinkButton ID="lnkYesterday" runat="server">Yesterday</asp:LinkButton>
                                </li>
                                <li>
                                    <asp:LinkButton ID="lnkThisWeek" runat="server">
                                        This Week&nbsp;&nbsp;<asp:Label ID="lblThisWeek" runat="server"></asp:Label>
                                    </asp:LinkButton>
                                </li>
                                <li>
                                    <asp:LinkButton ID="lnkLastWeek" runat="server">
                                        Last Week&nbsp;&nbsp;<asp:Label ID="lblLastWeek" runat="server"></asp:Label>
                                    </asp:LinkButton>
                                </li>
                                <li role="separator" class="divider"></li>
                                <li>
                                    <asp:LinkButton ID="lnkThisMonth" runat="server">
                                        This Month&nbsp;&nbsp;<asp:Label ID="lblThisMonth" runat="server"></asp:Label>
                                    </asp:LinkButton>
                                </li>
                                <li>
                                    <asp:LinkButton ID="lnkLastMonth" runat="server">
                                        Last Month&nbsp;&nbsp;<asp:Label ID="lblLastMonth" runat="server"></asp:Label>
                                    </asp:LinkButton>
                                </li>
                                <li role="separator" class="divider"></li>
                                <li><a id="acr" href="javascript:void(0);">Custom Range</a></li>
                                <li id="licustomranger" style="display:none;">
                                    <ul style="list-style-type:none; margin-left:-40px;">
                                        <li>
                                            <asp:TextBox ID="txtFrom" runat="server" CssClass="form-control input-sm" placeholder="From Date {YYYY-MM-DD}"></asp:TextBox>
                                        </li>
                                        <li>
                                            <asp:TextBox ID="txtTo" runat="server" CssClass="form-control input-sm" placeholder="To Date {YYYY-MM-DD}"></asp:TextBox>
                                        </li>
                                        <li>
                                            <asp:Button ID="btnCustomRange" runat="server" Text="Search" CssClass="btn btn-primary btn-xs" />
                                        </li>
                                    </ul>
                                </li>
                              </ul>
                            </div>
                            </div>
                        </div>                                             
                    </HeaderTemplate>
                    <ItemTemplate>
                        <div class="row" style="padding:15px; margin-top:2px;">
                            <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                              <asp:Label ID="CommentID" runat="server" Visible="false" Text='<%# Eval("CommentID") %>'></asp:Label>
                              <asp:CheckBox ID="chkChild" runat="server" />&nbsp;&nbsp;&nbsp;
                              <asp:HyperLink ID="hpkPostTitle" runat="server" Text='<%# Eval("PostTitle") %>' NavigateUrl='<%# GetRouteUrl("RoutetoGeneralSite", new { postID = Eval("PostID").ToString(), title = UserFriendlyURL.SeoURL(Eval("PostTitle").ToString()) }) %>'></asp:HyperLink>
                            </div>
                            <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                              <table>
                                  <tr>
                                      <td rowspan="4" style="vertical-align:top;padding:5px;">
                                          <asp:Image ID="CommentUserImage" runat="server" CssClass="img-rounded" Width="35px" Height="35px" ImageUrl='<%# GetRouteUrl("RoutetoProfilePicImage", new {userID=Eval("UserID").ToString(), username=Extension.Decrypt(Eval("Username").ToString()) }) %>' />
                                      </td>
                                      <td colspan="3" style="padding-left:10px;">
                                          <font color="Blue"><strong><asp:Label ID="CommentUserFullName" runat="server" Text='<%# Eval("FullName") %>'></asp:Label></strong></font>
                                          <span style="float:right;"><%# String.Format("{0:dddd, dd MMM yyyy}", Eval("CommentDate")) %> </span>
                                      </td>
                                  </tr>
                                  <tr>
                                      <td style="width:100%; padding-left:10px;">
                                          <asp:Label ID="lblCommentMessage" runat="server" Text='<%# Eval("CommentMessage") %>'></asp:Label><br />
                                          <a href="javascript:void(0);" onclick="showEdit(<%# Eval("CommentID") %>); return false;">Edit</a>&nbsp;&nbsp;<a href="javascript:void(0);" onclick="showReply(<%# Eval("commentID") %>); return false;">Reply</a><br />
                                          <div id='divEdit<%# Eval("CommentID") %>' style="display:none;">
                                           <asp:TextBox ID="txtEdit" runat="server" CssClass="form-control" TextMode="MultiLine" Text='<%# Eval("CommentMessage") %>'></asp:TextBox>
                                           <asp:Button ID="btnGridViewSaveEdit" CssClass="btn btn-primary btn-xs" runat="server" Text="Save Edit" style="margin-top:3px;"/>&nbsp;&nbsp;<a  class="btn btn-primary btn-xs" href="javascript:void(0);" onclick="CloseReplyEdit(<%# Eval("CommentID") %>); return false;">Close</a>
                                          </div>
                                          <div id='divReply<%# Eval("CommentID") %>' style="display:none;">
                                           <asp:TextBox ID="txtReply" runat="server" CssClass="form-control" TextMode="MultiLine"></asp:TextBox>
                                           <asp:Button ID="btnGridViewReply" runat="server" CssClass="btn btn-primary btn-xs" Text="Reply" style="margin-top:3px;"/>&nbsp;&nbsp;<a  class="btn btn-primary btn-xs" href="javascript:void(0);" onclick="CloseReplyEdit(<%# Eval("CommentID") %>); return false;">Close</a>
                                          </div>
                                      </td>
                                  </tr>
                                  <tr>
                                      <td style="padding:5px; width:100%;">
                                          <asp:LinkButton ID="lnkGridViewApproval" runat="server" style="padding:0 5px; font-size:12px;">
                                              <span class="glyphicon glyphicon-ok" aria-hidden="true"></span>&nbsp;Approve
                                          </asp:LinkButton>
                                          <asp:LinkButton ID="lnkGridViewSpam" runat="server" style="padding:0 5px; font-size:12px;">
                                              <span class="glyphicon glyphicon-ban-circle" aria-hidden="true"></span>&nbsp;Spam
                                          </asp:LinkButton>
                                          <asp:LinkButton ID="LinkButton1" runat="server" style="padding:0 5px; font-size:12px;">
                                              <span class="glyphicon glyphicon-trash" aria-hidden="true"></span>&nbsp;Delete
                                          </asp:LinkButton>
                                      </td>
                                  </tr>
                              </table>                              
                            </div>
                        </div>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <HeaderStyle CssClass="gridHeader" />
        </asp:GridView>
    </div>
  </div>
                </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="lnkCommentALL" EventName="Click" />
            <asp:AsyncPostBackTrigger ControlID="lnkCommentApproval" EventName="Click" />
            <asp:AsyncPostBackTrigger ControlID="lnkCommentPending" EventName="Click" />
            <asp:AsyncPostBackTrigger ControlID="lnkCommentSpam" EventName="Click" />
        </Triggers>
    </asp:UpdatePanel>

C#编码:

private void BindGrid()
        {
            DataSet ds = _commentPresenter.ShowAllCommentByUserID(Session["uid"].ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                GridComment.DataSource = ds;
                GridComment.DataBind();
                //UpdatePanel1.Update();
            }
            else
            {
                GridComment.EmptyDataText = "No Comments to Show";
                GridComment.DataBind();
                //UpdatePanel1.Update();
            }
        }


protected void lnkCommentALL_Click(object sender, EventArgs e)
        {
            BindGrid();
            licommentAll.Attributes.Add("class", "active");
            licommentApproval.Attributes.Add("class", "");
            licommentPending.Attributes.Add("class", "");
            licommentSpam.Attributes.Add("class", "");
            ScriptManager.RegisterStartupScript(this, GetType(), "Like", "var prm = Sys.WebForms.PageRequestManager.getInstance();   prm.add_endRequest(function() {  BindJavascript(); Like();  }); ", true);
        }

        protected void lnkCommentApproval_Click(object sender, EventArgs e)
        {
            DataSet ds = _commentPresenter.ShowAllApprovalComment(Session["uid"].ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                GridComment.DataSource = ds;
                GridComment.DataBind();
                licommentAll.Attributes.Add("class", ""); 
                licommentApproval.Attributes.Add("class", "active");
                licommentPending.Attributes.Add("class", "");
                licommentSpam.Attributes.Add("class", "");                
            }
            else
            {
                GridComment.EmptyDataText = "No Comments to Show";
                GridComment.DataBind();                
                licommentAll.Attributes.Add("class", "");
                licommentApproval.Attributes.Add("class", "active");
                licommentPending.Attributes.Add("class", "");
                licommentSpam.Attributes.Add("class", "");
            }
            ScriptManager.RegisterStartupScript(this, GetType(), "Like", "var prm = Sys.WebForms.PageRequestManager.getInstance();   prm.add_endRequest(function() {  BindJavascript(); Like();  }); ", true);
        }

        protected void lnkCommentPending_Click(object sender, EventArgs e)
        {
            DataSet ds = _commentPresenter.ShowAllPendingComment(Session["uid"].ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                GridComment.DataSource = ds;
                GridComment.DataBind();
                licommentAll.Attributes.Add("class", "");
                licommentApproval.Attributes.Add("class", "");
                licommentPending.Attributes.Add("class", "active");
                licommentSpam.Attributes.Add("class", "");
            }
            else
            {
                GridComment.EmptyDataText = "No Comments to Show";
                GridComment.DataBind();                
                licommentAll.Attributes.Add("class", "");
                licommentApproval.Attributes.Add("class", "");
                licommentPending.Attributes.Add("class", "active");
                licommentSpam.Attributes.Add("class", "");
            }
            ScriptManager.RegisterStartupScript(this, GetType(), "Like", "var prm = Sys.WebForms.PageRequestManager.getInstance();   prm.add_endRequest(function() {  BindJavascript(); Like();  }); ", true);
        }

        protected void lnkCommentSpam_Click(object sender, EventArgs e)
        {
            DataSet ds = _commentPresenter.ShowAllSpamComment(Session["uid"].ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                GridComment.DataSource = ds;
                GridComment.DataBind();
                licommentAll.Attributes.Add("class", "");
                licommentApproval.Attributes.Add("class", "");
                licommentPending.Attributes.Add("class", "");
                licommentSpam.Attributes.Add("class", "active");
            }
            else
            {
                GridComment.EmptyDataText = "No Comments to Show";
                GridComment.DataBind();
                licommentAll.Attributes.Add("class", "");
                licommentApproval.Attributes.Add("class", "");
                licommentPending.Attributes.Add("class", "");
                licommentSpam.Attributes.Add("class", "active");
            }
            ScriptManager.RegisterStartupScript(this, GetType(), "Like", "var prm = Sys.WebForms.PageRequestManager.getInstance();   prm.add_endRequest(function() {  BindJavascript(); Like();  }); ", true);
        }

0 个答案:

没有答案