如何在模式弹出窗口内编辑网格视图?
我有一个 gridview,它出现在动态生成的模式弹出窗口中,并绑定到动态生成的 SqlDataSource。
我这样做是希望利用 gridview 的自动编辑功能。
我的问题是,当单击编辑按钮时,尽管我的 gridview 位于更新面板中,但 modalpopup 由于完整回发而关闭...
我查看了解决方案 此处和此处 但都没有解决问题。我还尝试了所有关于 ModalPopupExtender 相对于更新面板等的定位的组合,并尝试将 UpdateMode 更改为条件。
标记:
<span class="none"><asp:Button ID="btnDummy" runat="server" Text="Dummy" /></span>
<ajax:ModalPopupExtender ID="mpLabel" runat="server" TargetControlID="btnDummy" BackgroundCssClass="modalBackground" PopupControlID="pnlLabels"></ajax:ModalPopupExtender>
<asp:Panel ID="pnlLabels" DefaultButton="btnOk" Style="display:none;" runat="server">
<div style="background-color:#fff;border:1px solid black;padding:7px;">
<asp:UpdatePanel ID="upLabels" runat="server" ChildrenAsTriggers="true" EnableViewState="true" UpdateMode="Always">
<ContentTemplate>
<asp:Panel ID="pnlGv" runat="server" style="max-height:420px;width:700px;border-bottom:1px #ccc solid;" ScrollBars="Vertical">
<asp:PlaceHolder ID="phLabelInfo" runat="server"></asp:PlaceHolder>
<asp:PlaceHolder ID="phSDS" runat="server"></asp:PlaceHolder>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="btnOk" runat="server" Text="Ok" />
</div>
</asp:Panel>
代码隐藏:
Dim sdsLabels As New SqlDataSource
sdsLabels.ID = "sdsLabels"
sdsLabels.ConnectionString = System.Configuration.ConfigurationManager.AppSettings.Get("Generic Connection String")
sdsLabels.ProviderName = "System.Data.SqlClient"
sdsLabels.DeleteCommand = "DELETE FROM [JS_LABELS] WHERE [LABELID] = @LabelId"
sdsLabels.SelectCommand = "SELECT [LABELID], [CIRCUITNUMBER], [PANELNUMBER], [ADDITIONAL1], [ADDITIONAL2], [ADDITIONAL3] FROM [JS_LABELS] WHERE [QUOTEITEMID] = @QuoteItemId"
sdsLabels.UpdateCommand = "UPDATE [JS_LABELS] SET [CIRCUITNUMBER] = @CircuitNumber, [PANELNUMBER] = @PanelNumber, [ADDITIONAL1] = @Additional1, [ADDITIONAL2] = @Additional2, [ADDITIONAL3] = @Additional3 WHERE [LABELID] = @LABELID"
sdsLabels.SelectParameters.Add(New Parameter("QuoteItemId", Data.DbType.Int32, e.CommandArgument.ToString()))
sdsLabels.DeleteParameters.Add(New Parameter("LabelId", Data.DbType.Int32))
Dim paramCollection As New ParameterCollection
paramCollection.Add("CircuitNumber", Data.DbType.String, "")
paramCollection.Add("PanelNumber", Data.DbType.String, "")
paramCollection.Add("Additional1", Data.DbType.String, "")
paramCollection.Add("Additional2", Data.DbType.String, "")
paramCollection.Add("Additional3", Data.DbType.String, "")
paramCollection.Add("LabelId", Data.DbType.Int32, "0")
Dim ph As New PlaceHolder
ph = CType(PageHelper.RecursiveFindControl(Page, "phSDS"), PlaceHolder)
ph.Controls.Add(sdsLabels)
Dim gv As New GridView
ph = CType(PageHelper.RecursiveFindControl(Page, "phLabelInfo"), PlaceHolder)
ph.Controls.Add(gv)
gv.CssClass = "LabelsTable"
Dim LabelId() As String = {"LabelId"}
gv.DataKeyNames = LabelId
gv.EnableViewState = True
gv.AutoGenerateEditButton = True
AddHandler gv.RowCommand, AddressOf gv_rowCommand
gv.DataSourceID = sdsLabels.ID
gv.DataBind()
mpLabel.Show()
I have a gridview that appears in a modal popup that is generated dynamically and is bound to a dynamically generated SqlDataSource.
I did this to hopefully take advantage of the gridview's automatic editing capabilities.
My problem is that when the edit button is clicked the modalpopup closes due to a full postback in spite of the fact that my gridview is in an update panel...
I looked at solutions here and here but neither fixed the problem. I've also tried every combination under the sun regarding the positioning of the ModalPopupExtender in relation to the update panel etc, and have tried changing UpdateMode to conditional as well.
Markup:
<span class="none"><asp:Button ID="btnDummy" runat="server" Text="Dummy" /></span>
<ajax:ModalPopupExtender ID="mpLabel" runat="server" TargetControlID="btnDummy" BackgroundCssClass="modalBackground" PopupControlID="pnlLabels"></ajax:ModalPopupExtender>
<asp:Panel ID="pnlLabels" DefaultButton="btnOk" Style="display:none;" runat="server">
<div style="background-color:#fff;border:1px solid black;padding:7px;">
<asp:UpdatePanel ID="upLabels" runat="server" ChildrenAsTriggers="true" EnableViewState="true" UpdateMode="Always">
<ContentTemplate>
<asp:Panel ID="pnlGv" runat="server" style="max-height:420px;width:700px;border-bottom:1px #ccc solid;" ScrollBars="Vertical">
<asp:PlaceHolder ID="phLabelInfo" runat="server"></asp:PlaceHolder>
<asp:PlaceHolder ID="phSDS" runat="server"></asp:PlaceHolder>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="btnOk" runat="server" Text="Ok" />
</div>
</asp:Panel>
Code Behind:
Dim sdsLabels As New SqlDataSource
sdsLabels.ID = "sdsLabels"
sdsLabels.ConnectionString = System.Configuration.ConfigurationManager.AppSettings.Get("Generic Connection String")
sdsLabels.ProviderName = "System.Data.SqlClient"
sdsLabels.DeleteCommand = "DELETE FROM [JS_LABELS] WHERE [LABELID] = @LabelId"
sdsLabels.SelectCommand = "SELECT [LABELID], [CIRCUITNUMBER], [PANELNUMBER], [ADDITIONAL1], [ADDITIONAL2], [ADDITIONAL3] FROM [JS_LABELS] WHERE [QUOTEITEMID] = @QuoteItemId"
sdsLabels.UpdateCommand = "UPDATE [JS_LABELS] SET [CIRCUITNUMBER] = @CircuitNumber, [PANELNUMBER] = @PanelNumber, [ADDITIONAL1] = @Additional1, [ADDITIONAL2] = @Additional2, [ADDITIONAL3] = @Additional3 WHERE [LABELID] = @LABELID"
sdsLabels.SelectParameters.Add(New Parameter("QuoteItemId", Data.DbType.Int32, e.CommandArgument.ToString()))
sdsLabels.DeleteParameters.Add(New Parameter("LabelId", Data.DbType.Int32))
Dim paramCollection As New ParameterCollection
paramCollection.Add("CircuitNumber", Data.DbType.String, "")
paramCollection.Add("PanelNumber", Data.DbType.String, "")
paramCollection.Add("Additional1", Data.DbType.String, "")
paramCollection.Add("Additional2", Data.DbType.String, "")
paramCollection.Add("Additional3", Data.DbType.String, "")
paramCollection.Add("LabelId", Data.DbType.Int32, "0")
Dim ph As New PlaceHolder
ph = CType(PageHelper.RecursiveFindControl(Page, "phSDS"), PlaceHolder)
ph.Controls.Add(sdsLabels)
Dim gv As New GridView
ph = CType(PageHelper.RecursiveFindControl(Page, "phLabelInfo"), PlaceHolder)
ph.Controls.Add(gv)
gv.CssClass = "LabelsTable"
Dim LabelId() As String = {"LabelId"}
gv.DataKeyNames = LabelId
gv.EnableViewState = True
gv.AutoGenerateEditButton = True
AddHandler gv.RowCommand, AddressOf gv_rowCommand
gv.DataSourceID = sdsLabels.ID
gv.DataBind()
mpLabel.Show()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据我的经验,ModalPopupExtender 将始终在回发时关闭,除非您明确要求它在回发触发的事件中不要关闭:
In my experiences, the ModalPopupExtender will always close on a postback unless you explicitly ask it not to in the event triggered by the postback: