在asp.net中单击gridview按钮时如何填充modalpopupextender
我有一个问题,也许有人可以帮助我。 我有一个 gridview 和一个按钮,可以从 modalpopupextender 中编辑 gridview 中的字段。 我想要实现的是,当有人单击编辑按钮时,弹出窗口会显示需要编辑的行中的数据。 就像现在一样,当有人单击编辑按钮时,会出现弹出窗口,但其中有空白文本框/下拉菜单。 这是我现在所拥有的:
<ItemTemplate>
<asp:Button ID="btnEdit" CausesValidation="false"
runat="server" Text="Edit" OnClick="Activatee" />
<ajaxToolkit:ConfirmButtonExtender ID="btnDeactivatePopup" runat="server"
TargetControlID="btnEdit" DisplayModalPopupID="ModalPopupDeactivate" />
<ajaxToolkit:ModalPopupExtender
ID="ModalPopupDeactivate" runat="server" TargetControlID="btnEdit"
PopupControlID="pnlActivate" OkControlID="btnDeactivateOK"
CancelControlID="btnDeactivateCancel" BackgroundCssClass="modalBackground"
DynamicServicePath="" Enabled="true" />
</ItemTemplate>
单击按钮时我尝试了另一种方法,但是当我单击编辑按钮时,页面上没有出现弹出窗口:
<ItemTemplate>
<asp:Button ID="btnEdit" CausesValidation="false"
runat="server" Text="Edit" OnClick="getData" />
<!--
<ajaxToolkit:ConfirmButtonExtender ID="btnDeactivatePopup"
runat="server" TargetControlID="btnEdit"
DisplayModalPopupID="ModalPopupDeactivate" />
-->
<ajaxToolkit:ModalPopupExtender ID="ModalPopupDeactivate"
runat="server" TargetControlID="btnEdit" PopupControlID="pnlActivate"
OkControlID="btnDeactivateOK" CancelControlID="btnDeactivateCancel"
BackgroundCssClass="modalBackground" DynamicServicePath="" Enabled="true" />
</ItemTemplate>
这里也是该版本的后端代码上面,但最后没有显示弹出窗口:
protected void getData(object sender, EventArgs e)
{
string coef = "";
Button btn = (Button)sender;
GridViewRow gvr = (GridViewRow)btn.NamingContainer;
int rowindex = gvr.RowIndex;
GridViewRow roww = gvGDG.Rows[rowindex];
coef = Convert.ToString(roww.Cells[7].Text);
txtCoefficient.Text = coef;
ModalPopupExtender modalPopupExtender1 =
(ModalPopupExtender)gvGDG.Rows[rowindex].FindControl("ModalPopupDeactivate");
modalPopupExtender1.Show();
}
我希望有人可以帮助我解决这个问题。 非常感谢,拉齐亚莱
I have one problem, someone maybe can help me.
I have a gridview and a button to edit the fields in the gridview from within a modalpopupextender.
What I want to achieve is when someone will click the edit button, the popup to have the data from the row which needs to be edited.
As it is now, when someone clicks the edit button, the popup comes up but with blank textboxes/dropdowns there.
Here is what I have at this moment:
<ItemTemplate>
<asp:Button ID="btnEdit" CausesValidation="false"
runat="server" Text="Edit" OnClick="Activatee" />
<ajaxToolkit:ConfirmButtonExtender ID="btnDeactivatePopup" runat="server"
TargetControlID="btnEdit" DisplayModalPopupID="ModalPopupDeactivate" />
<ajaxToolkit:ModalPopupExtender
ID="ModalPopupDeactivate" runat="server" TargetControlID="btnEdit"
PopupControlID="pnlActivate" OkControlID="btnDeactivateOK"
CancelControlID="btnDeactivateCancel" BackgroundCssClass="modalBackground"
DynamicServicePath="" Enabled="true" />
</ItemTemplate>
I tried with another method when the button is clicked, but when I am clicking the edit button, the popup doesn't come out at the page:
<ItemTemplate>
<asp:Button ID="btnEdit" CausesValidation="false"
runat="server" Text="Edit" OnClick="getData" />
<!--
<ajaxToolkit:ConfirmButtonExtender ID="btnDeactivatePopup"
runat="server" TargetControlID="btnEdit"
DisplayModalPopupID="ModalPopupDeactivate" />
-->
<ajaxToolkit:ModalPopupExtender ID="ModalPopupDeactivate"
runat="server" TargetControlID="btnEdit" PopupControlID="pnlActivate"
OkControlID="btnDeactivateOK" CancelControlID="btnDeactivateCancel"
BackgroundCssClass="modalBackground" DynamicServicePath="" Enabled="true" />
</ItemTemplate>
And here is the backend code too for the version above but it doesn't show the popup at the end:
protected void getData(object sender, EventArgs e)
{
string coef = "";
Button btn = (Button)sender;
GridViewRow gvr = (GridViewRow)btn.NamingContainer;
int rowindex = gvr.RowIndex;
GridViewRow roww = gvGDG.Rows[rowindex];
coef = Convert.ToString(roww.Cells[7].Text);
txtCoefficient.Text = coef;
ModalPopupExtender modalPopupExtender1 =
(ModalPopupExtender)gvGDG.Rows[rowindex].FindControl("ModalPopupDeactivate");
modalPopupExtender1.Show();
}
I hope someone can help me with this.
Thanks a lot, Laziale
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于 Pauls 链接不再有效,这里是 SO
GridView 内 ImageButton 上的 PopUpExtender 问题
答案中的链接与 Paul 的答案来源相同,当我检查时,它们也已失效。但该答案中有代码摘要。那应该对你有帮助。
As Pauls link is no longer working, here is an answer to a similar question on SO
PopUpExtender on ImageButton inside GridView problem
The links in the answer are to the same source as Pauls answer and when I checked they are dead too. But there is a summary of the code in that answer. That should help you.
这里是我学习如何使用 ModalPopupExtender 的地方。也许值得阅读这个示例并看看它是否适合您的场景。
我认为通过查看代码,将 modalpopup 的关联按钮设置为 gridview 行控件会导致问题。
Here is where I learned how to use ModalPopupExtender. Perhaps worth reading this example and seeing if it fits your scenario.
I would think from looking at the code, that setting the modalpopup's associated button to a gridview row control would cause an issue.
我过去所做的是在每行添加一个“Edit”
UserControl
设置为display:none
并绑定所有属性,以便当它由 modalpopupextener 显示时,一切都很好。然后,您可以在UserControl
中处理回发,该回发将具有您需要的所有状态:What I have done in the past is add a "Edit"
UserControl
per row set todisplay:none
and bind all the properties, so that when it's shown by the modalpopupextener, it's all good. You then handle the postback in theUserControl
that will have all the state you need: