单击网格中的LinkBut​​ton时避免页面刷新

时间:2015-09-30 05:45:41

标签: c# html

我有GridView控件,在此控件内部我使用GridView.ItemTemplate定义了一个链接按钮。

我使用它在点击时打开一个新窗口。但是,当我点击链接按钮时,页面会在打开新窗口之前刷新。

单击链接按钮后如何停止刷新页面?

将“更新”面板添加到第一个网格

时,弹出窗口不显示

如果我从第一个网格中删除“更新”面板,则网格正在刷新,弹出窗口正在显示

我需要在不刷新网格的情况下打开弹出窗口

请我找到解决方案,因为我已经过了2天的工作

HTML

<%@ Page Language="c#" AutoEventWireup="false" CodeFile="ViewData1.aspx.cs" Inherits="ablesas.ViewDataUI1" EnableEventValidation="false"%>


            <asp:UpdatePanel ID="UpdatePanel4" runat="server">
                        <ContentTemplate>

                                         <asp:GridView ID="DataGrid1"  style="visibility:visible" runat="server" AlternatingRowStyle-BackColor="#E9EDF5"  Font-Names="Arial"
                                                ForeColor="#09538A" Font-Size="12px" BackColor="#ffffff" BorderColor="DarkGray" Font-Bold="true" 
                                                HeaderStyle-BackColor="#298DC7" EnableViewState="false"  CellSpacing="20" 
                                                CellPadding="10"  HeaderStyle-Font-Bold="true"  AutoGenerateColumns="False" OnRowCommand="DataGrid1__RowCommand" OnRowDataBound="DataGrid1__RowDataBound" >
                                                <HeaderStyle Font-Names="Arial;" CssClass="MyHeaderStyle" Font-Size="13px" ForeColor="White" Font-Bold="True" Height="20"  BackColor="#298DC7" ></HeaderStyle>
        <asp:templatefield headertext="NDC" ItemStyle-CssClass="col" ItemStyle-HorizontalAlign="Justify" HeaderStyle-Width="10%" ItemStyle-Width="10%">                                     <Columns>               
                    <itemtemplate>
                    <asp:linkbutton id="productcode"   ForeColor="#09538A" runat="server"  text='<%#Eval("product code")%>'></asp:linkbutton>                               

                                                     </itemtemplate>
                                        </asp:templatefield>
                   </asp:GridView>
                                </ContentTemplate>
                </asp:UpdatePanel>


                                        <AjaxToolkit:ModalPopupExtender ID="ModalPopupExtender1"   BackgroundCssClass="modalBackground" CancelControlID="cancel" TargetControlID="Button3" runat="server" PopupControlID="pnlpopup"> </AjaxToolkit:ModalPopupExtender>
    <asp:Panel id="Panel1"  runat="server" Height="30px" Width="600px">
    </asp:Panel>        
                   <asp:Button ID="Button3" runat="server" style="visibility:hidden" Text="Button" />
                            <asp:Panel ID="pnlpopup" CssClass="PanelPopup"  runat="server">
                                        <div  style="width:inherit;text-align:center;">Products of <%=ndc %> Product Family</div>
                                        <asp:GridView ID="GridView1"  runat="server" AlternatingRowStyle-BackColor="#f1f4f8"  Width="980px" Font-Names="Arial"
                                            Font-Bold="True" ForeColor="#09538A" Font-Size="13px" BackColor="#ffffff" BorderColor="DarkGray"
                                            HeaderStyle-BackColor="#99cccc" EnableViewState="false"  CellSpacing="0" style="padding:10px;"
                                            CellPadding="3" ShowFooter="false" AllowPaging="True" AutoGenerateColumns="False" OnRowDataBound="productInfo_RowDataBound" >
                                            <HeaderStyle Height="10%" CssClass="MyHeaderStyle" Font-Size="13px" ForeColor="#FFFFFF" Font-Bold="true"  BackColor="#298DC7"></HeaderStyle>
                                            <rowstyle Height="20px" />
                        <alternatingrowstyle  Height="20px"/>
                                            <Columns>
                <asp:boundfield  datafield="product code" sortexpression="customers " ItemStyle-CssClass="col" headertext="NDC"/>

             <div id="div<%#  Convert.ToString(Eval("customer"))+ Convert.ToString(Eval("ManufacturingPartner"))+ Convert.ToString(Eval("product code"))+ Convert.ToString(Eval("Sales Person")) %>" style="display: none; position: relative; left: 15px; overflow: auto">
                                        <asp:GridView ID="gvOrderInfo" runat="server" ForeColor="#09538A"  AutoGenerateColumns="false" BorderStyle="Double"  BorderColor="#df5015"  Width="500px" OnRowDataBound="gvOrderInfo_RowDatabound">
                                        <HeaderStyle CssClass="MyHeaderStyle"  Font-Size="13px" ForeColor="#FFFFFF" Font-Bold="True"  BackColor="#298DC7"></HeaderStyle>
                                        <RowStyle BackColor="#E1E1E1" />
                                        <AlternatingRowStyle BackColor="White" />
                                        <HeaderStyle BackColor="#df5015" Font-Bold="true" ForeColor="White" />
                                        <Columns>
              <asp:BoundField DataField="Order Number" HeaderText="Order Number" ItemStyle-Width="75px" ItemStyle-CssClass="col" HeaderStyle-HorizontalAlign="Left" />
                  </Columns>   
              </Columns>                            
                                        </asp:GridView>
                                    </div>                         
                                            </asp:GridView>
             </asp:Panel>

代码隐藏

  protected void DataGrid1__RowDataBound(Object sender, GridViewRowEventArgs e)
    {    
         this.UpdatePanel4.Update();
         if (e.Row.RowType == DataControlRowType.DataRow)
         {
              LinkButton lnk = e.Row.FindControl("productcode") as LinkButton;
              lnk.Click += new EventHandler(link_Click);

              //ScriptManager.GetCurrent(this).RegisterPostBackControl(lnk); 

              // string a = String.Format("0:N}",Convert.ToDecimal(e.Row.Cells[3].Text));
              if (e.Row.Cells[0].Text != "Total")
              {
                    //M1-Fmodification starts from here
                    if (ListBox2.Items.Count > 0)
                    //if (DataGrid1.Columns[0].Visible == true)
                    {
                    }              
              }
         }
    }

代码隐藏

 public void productcode_Click(object sender, EventArgs e)
        {
            pnlpopup.Visible = true;
            //UpdatePanel3.Update();
            //this.UpdatePanel3.Update();
            GridViewRow clickedRow = ((LinkButton)sender).NamingContainer as GridViewRow;
            LinkButton lbtn = (LinkButton)clickedRow.FindControl("productcode");
            string customer = clickedRow.Cells[0].Text.ToString();
            string manufacturer = clickedRow.Cells[5].Text.ToString();
            string salesperson = clickedRow.Cells[6].Text.ToString();
            System.Data.DataTable newProductTable = null;
            ArrayList productDrilldownList = new ArrayList();
            productDrilldownList.Add(customer);
            productDrilldownList.Add(manufacturer);
            productDrilldownList.Add(lbtn.Text);
            productDrilldownList.Add(salesperson);


            try
            {
                ViewData1 vData = new ViewData1();
                DataSet ds1 = vData.__getProdOverviewDataSet(__getConnectionString());
                DataSet ds2 = vData.__getCustOverviewDataSet(__getConnectionString());
                DataSet ds3 = vData.__getSalesOverviewDataSet(__getConnectionString());
                DataSet ds4 = vData.__getManOverviewDataSet(__getConnectionString());
                DataSet ds5 = vData.__getBookedDateDataSet(__getConnectionString());

                List<DateTime> booked_date = new List<DateTime>();

                if (ds5.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow row in ds5.Tables[0].Rows)
                    {
                        if (row[0].ToString() != " " && row[0] != null)
                        {
                            booked_date.Add(Convert.ToDateTime(row[0]));
                        }
                    }
                }
                booked_date.Remove(Convert.ToDateTime("1/1/0001 12:00:00 AM"));
                booked_date.Sort();
                ArrayList daterange = new ArrayList();
                daterange = _getDateRange();
                if (Convert.ToDateTime(daterange[0]) > Convert.ToDateTime(daterange[1]))
                {
                 //   DataGrid1.Visible = false;
                 //   Label4.Visible = false;
                //    TxtCustProd.Visible = false;
                //    Panel1.Visible = false;
                //    ClientScript.RegisterClientScriptBlock(GetType(), "Javascript", "<script>alert('There is no data found')</script>");
                //    return;
                }
                if (ToDateTxtBox.Text != "" && ToDateTxtBox.Text != "To Date" && FromDateTxtBox.Text != "From Date")
                {
                    DropDownList2.Text = "Months";
                    DropDownList3.Text = "Years";
                    if (!booked_date.Contains(Convert.ToDateTime(daterange[2])) && !booked_date.Contains(Convert.ToDateTime(daterange[3])))
                    {
                     //   DataGrid1.Visible = false;
                     //   Label4.Visible = false;
                    //    TxtCustProd.Visible = false;
                    //    Panel1.Visible = false;
                    //    ClientScript.RegisterClientScriptBlock(GetType(), "Javascript", "<script>alert('There is no data found')</script>");
                    }
                }
                else
                {
                    ToDateTxtBox.Text = "";
                    FromDateTxtBox.Text = "";
                }




                int countCustomer = -1;
                int countProduct = -1;
                int countSales = -1;
                int countMan = -1;
                if (ds1.Tables[0].Rows.Count > 0)
                {
                    countProduct = ds1.Tables[0].Rows.Count;
                }
                if (ds2.Tables[0].Rows.Count > 0)
                {
                    countCustomer = ds2.Tables[0].Rows.Count;
                }
                if (ds3.Tables[0].Rows.Count > 0)
                {
                    countSales = ds3.Tables[0].Rows.Count;
                }
                if (ds4.Tables[0].Rows.Count > 0)
                {
                    countMan = ds4.Tables[0].Rows.Count;
                }


                System.Data.DataTable dt = new System.Data.DataTable();
                string test = "";
                if(Session["callcount"] != null){
                    string coo = Session["callcount"].ToString(); 
                    int coi = Int16.Parse(coo);
                    Session["callcount"] = coi + 1;
                    test = Session["callcount"].ToString();
                }
                else{
                    int coi = 0;
                    Session["callcount"] = coi.ToString();
                    test = Session["callcount"].ToString();
                }
                dt = vData.__getProductLevelSource(__getConnectionString(), __getDropDownValues(), __getProdFilterValues(), __getCustFilterValues(), __getSalesFilterValues(), __getManFilterValues(), countCustomer, countProduct, countSales, countMan, _getDateRange(), __getProdFamilyFilterValues(), productDrilldownList);
                GridView1.DataSource = dt;
                GridView1.DataBind();
                //dt.Rows.Count
                Gridview_Columnshide(GridView1);
            }
            catch (Exception dateerr)
            {
                //DataGrid1.Visible = false;
                //Label4.Visible = false;
                //TxtCustProd.Visible = false;
                //Panel1.Visible = false;
                //ClientScript.RegisterClientScriptBlock(GetType(), "Javascript", "<script>alert('There is no data found')</script>");

            }

            ModalPopupExtender1.Show();
            //UpdatePanel3.Update();

        }

1 个答案:

答案 0 :(得分:2)

请尝试在更新面板中添加模型弹出扩展器。然后会弹出页面刷新。这是一个示例代码。这个没有任何问题。再来看一次

  <asp:UpdatePanel runat="server">
    <ContentTemplate>



        <asp:GridView ID="DataGrid1" runat="server" OnRowDataBound="DataGrid1__RowDataBound">

            <Columns>
                <asp:BoundField DataField="ID" HeaderText="Value" />
                <asp:TemplateField HeaderText="NDC" ItemStyle-CssClass="col" ItemStyle-HorizontalAlign="Justify" HeaderStyle-Width="10%" ItemStyle-Width="10%">

                    <ItemTemplate>
                        <asp:LinkButton ID="productcode" ForeColor="#09538A" runat="server" Text='click'></asp:LinkButton>

                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>



        <AjaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" TargetControlID="Button3" runat="server" PopupControlID="pnlpopup"></AjaxToolkit:ModalPopupExtender>

        <asp:Button ID="Button3" runat="server" Style="visibility: hidden" Text="Button" />
        <asp:Panel ID="pnlpopup" CssClass="model-bd" runat="server">
            <input type="button" value="ok">
        </asp:Panel>
    </ContentTemplate>
</asp:UpdatePanel>

---------- C#------------

   protected void Page_Load(object sender, EventArgs e)
    {

        DataTable dt = new DataTable();
        dt.Columns.Add("ID");
        DataRow dr = dt.NewRow();
        DataRow dr1 = dt.NewRow();
        dr["ID"] = 1;
        dr1["ID"] =21;
        DataGrid1.DataSource = dt;
        dt.Rows.Add(dr);
        dt.Rows.Add(dr1);
        DataGrid1.DataBind();
    }
    protected void DataGrid1__RowDataBound(Object sender, GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton lnk = e.Row.FindControl("productcode") as LinkButton;
            lnk.Click += new EventHandler(productcode_Click);


        }
    }
     void productcode_Click(object sender, EventArgs e)
    {
        pnlpopup.Visible = true;



        ModalPopupExtender1.Show();


    }