gpt4 book ai didi

c# - 当 Gridview 在更新面板内时,模态弹出窗口无法正常工作

转载 作者:太空宇宙 更新时间:2023-11-03 16:06:33 25 4
gpt4 key购买 nike

我有一个带有链接按钮的 GridView ,当您单击它时,会出现一个模态弹出窗口,其中包含所单击行的详细信息。如果 gridview 不在更新面板中,这可以正常工作。我必须每秒更新一次 gridview。如果我使用更新面板,模式弹出窗口显示为空白。关于如何让它在更新面板中工作的任何想法?

<div class="Info">
<asp:UpdatePanel ID="UpdatePanelMain" runat="server" UpdateMode="Conditional">
<ContentTemplate>

<asp:GridView ID="gvMain" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None"
Width="688px" AllowPaging="True" AutoGenerateColumns="false" OnSelectedIndexChanged="gvMain_SelectedIndexChanged"
Font-Size="14px" PageSize="8" DataKeyNames="TicketId, TicketNumber"
OnRowCommand="gvMain_RowCommand" OnPageIndexChanging="gvMain_PageIndexChanging"
OnRowDataBound="gvMain_RowDataBound">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="TicketId" HeaderText="Id" SortExpression="TicketId"
Visible="false">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="TicketNumber" HeaderText="Ticket #Id" SortExpression="TicketNumber"
Visible="false">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="DisplayNum" HeaderText="Ticket Number" SortExpression="DisplayNum">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lbTicketInfo" runat="server" CommandName="Popup" OnClick="lblTicketInfo_Click">LinkButton</asp:LinkButton>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="TimerGVMain" />
</Triggers>
</asp:UpdatePanel>
<asp:Timer ID="TimerGVMain" Interval="1000" runat="server" OnTick="TimerGVMain_Tick">
</asp:Timer>
<%--Used for modal popup--%>
<asp:Button ID="btnTarget" runat="server" Style="display: none;" />
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnTarget"
PopupControlID="Div1" DropShadow="True" CancelControlID="btnCloseModal" Drag="True">
</asp:ModalPopupExtender>
<div id="Div1" runat="server" style="background-color: #5D7B9D; color: White; border: #284775 3px solid;
width: 300px; height: 150px; font-size: 10pt; font-family: Verdana;">
<asp:Label ID="Label2" runat="server" Text=""></asp:Label>
<asp:GridView ID="gvTicketInfo" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None"
AutoGenerateColumns="False">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="Desc" HeaderText="Trans Type" SortExpression="Desc" />
<asp:BoundField DataField="Time" HeaderText="Est Trans Time" SortExpression="Time" />
</Columns>
</asp:GridView>
<%--Button used to close Modal Pop up--%>
<asp:Button ID="btnCloseModal" runat="server" Text="Close" />
</div>

aspx.cs

 protected void gvMain_RowCommand(object sender, GridViewCommandEventArgs e)
{
RowIndex = Convert.ToInt32(e.CommandArgument);

if (e.CommandName == "Popup" && e.CommandArgument != null)
{

string displayNo = gvMain.Rows[RowIndex].Cells[3].Text;
//string displayNo = gvMain.DataKeyNames[RowIndex]["DisplayNum"].ToString();
ModalPopupExtender1.Show();
try
{
using (SqlConnection cs = new SqlConnection(connStr))
{
SqlDataAdapter da = new SqlDataAdapter("spClerkUI_ShowAllTrans_inTicket", cs);
da.SelectCommand.CommandType = System.Data.CommandType.StoredProcedure;
da.SelectCommand.Parameters.AddWithValue("@Location", qStatic);
da.SelectCommand.Parameters.AddWithValue("@DisplayNum", displayNo);

DataSet ds = new DataSet();
da.Fill(ds);
gvTicketInfo.DataSource = ds;
gvTicketInfo.DataBind();

Label1.Text = string.Format("<Br>Row # {0}", RowIndex);
}
}
catch (Exception ex)
{
lblStatus.Text = "Modal Error: " + ex.ToString();
}
}

}

protected void gvMain_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton ImageButtonTicketInfo = (LinkButton)e.Row.FindControl("lbTicketInfo");
ImageButtonTicketInfo.CommandArgument = e.Row.RowIndex.ToString();
}
}

最佳答案

在页面目录后添加

<%@ Register TagPrefix="ajaxToolkit" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit" %>

并将 ModalPopupExtender1.Show(); 放在 try block 中

并添加

Div1.Visible = true;    
gvTicketInfo.Visible = true;

关于c# - 当 Gridview 在更新面板内时,模态弹出窗口无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19161057/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com