我有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();
}
答案 0 :(得分:0)
检查DataGrid1.Datsource
中是否有DataGrid1.Databind();
和onPage_Load()
因为当你按下按钮时会调用它。
DataGrid1.DataSource = ...;
与DataGrid1.DataBind();
结合使用,可将gridview中的所有值更新为已定义列表中的值。
这意味着当你在onPage_Load()
中拥有它时,它将刷新gridview。
答案 1 :(得分:0)
这里的结构:
首先,如果您使用的是母版页,请将其置于页面顶部,ContentPlaceHolder1
下方,如果您不是
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></ajaxToolkit:ToolkitScriptManager>
接下来,我们创建一个UpdatePanel,页面中的EVERYTHING将放在INSIDE这个UpdatePanel中(你可以有其他UpdatePanel,但这是外部的)这将确保页面不会刷新/重新加载任何点击事件({此外部UpdatePanel不需要{1}}。使用<trigger>
作为ModalPopupExternder的TargetCOntrolID instaed of button。
HiddenField
不要使用UpdatePanel.Update()函数,如果要更新gridview,请更新数据集并调用Gridview.Databind()方法。
如果你想在ModalPopupExtender中使用其他UpdatePanel,只需将所有内容都放在Panel中,但这次你需要<asp:UpdateProgress ID="UpdateProgress1" DisplayAfter="10" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<div style="position: absolute; visibility: visible; border: none; z-index: 100; width: 100%; height: 100%; background: #999; filter: alpha(opacity=80); -moz-opacity: .8; opacity: .8;">
<img src="http://www.ajaxload.info/images/exemples/29.gif" style="top: 50%; left: 50%; position: relative;" />
</div>
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
//all your contents will be here
//Your DataGrid1 with LinkButton inside...
<AjaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" BackgroundCssClass="modalBackground" CancelControlID="cancel" TargetControlID="HiddenField1" runat="server" PopupControlID="pnlpopup"> </AjaxToolkit:ModalPopupExtender>
<asp:HiddenField ID="HiddenField1" runat="server" />
// Your pnlpopup Panel
</ContentTemplate>
<Triggers>
</Triggers>
</asp:UpdatePanel>
来获取这个UpdatePanel中的按钮(而不是取消/关闭弹出按钮)