ModalPopupExtender里面一个GridView的ItemTemplate [英] ModalPopupExtender inside a GridView ItemTemplate

查看:123
本文介绍了ModalPopupExtender里面一个GridView的ItemTemplate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用含有一个LinkBut​​ton是要显示在点击的模式一个GridView模板列?我有我想更新一下该行中的编辑的LinkBut​​ton时的细节数据行。有一组数据,我需要通过codebehind刚模态显示之前加载。

How do I use a GridView TemplateField containing a LinkButton that is to display the modal on click? I have rows of data that I want to update the details of when clicking the 'Edit' LinkButton in that row. There is a bunch of data I need to load via codebehind just before the Modal displays.

我试着以下,但我不能做 Modal1.Show()在事件处理程序,因为它是在一个TemplateField:

I was trying the following, but I can't do Modal1.Show() in the event handler because it's in a TemplateField:

<ItemTemplate>
  <asp:Button runat="server" ID="HiddenForModal" style="display: none" />
    <ajaxToolkit:ModalPopupExtender ID="Modal1" runat="server" TargetControlID="HiddenForModal" PopupControlID="pnlModal" />
    <asp:LinkButton ID="btnEdit" runat="server" Text="Edit" onclick="btnEdit_Click" />
    <asp:LinkButton ID="btnDelete" runat="server" Text="Delete"></asp:LinkButton>
</ItemTemplate>

谢谢, 马克

Thanks, Mark

推荐答案

关键是要知道这在GridView控件一行是被点击LinkBut​​ton的。为此,您可以几种方法,但我的方式实现它捕捉到它在RowCommand事件。然后你就可以通过的FindControl访问ModalPopupExtender的点击行(..)。

The key is knowing which row in the GridView was the LinkButton that was clicked. You can do this several ways but the way I implemented it is to capture it in the RowCommand event. Then you can access the ModalPopupExtender in the clicked row via FindControl(..).

页:

<asp:TemplateField>
  <ItemTemplate>
    <asp:Button ID="Button1" runat="server" style="Display:none;" Text="Button" />
    <cc1:ModalPopupExtender ID="ModalPopupExtender1" PopupControlID="Popup1" TargetControlID="Button1" BackgroundCssClass="modalBackground" runat="server" />
    <asp:LinkButton ID="LinkButton1" CommandName="Popup" runat="server">Popup</asp:LinkButton>
  </ItemTemplate>
</asp:TemplateField>

codebehind:

Codebehind:

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

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Popup" && e.CommandArgument != null)
        {
            int rowIndex = Convert.ToInt32(e.CommandArgument);
            ModalPopupExtender modalPopupExtender1 = (ModalPopupExtender)GridView1.Rows[rowIndex].FindControl("ModalPopupExtender1");
            modalPopupExtender1.Show();

            //Perform any specific processing.
            Label1.Text = string.Format("Row # {0}", rowIndex);
        }
    }

此外,因为你是在回发开模态反正你实际上并不需要的ModalPopupExtender(或隐藏的按钮)在ItemTemplate。您可以移动了这一点,并把它放在网页上(由您的弹出DIV),并可以简单地调用Show()方法。

Additionally, because you are opening the modal on a postback anyways you don't actually need the ModalPopupExtender (or the hidden button) in the ItemTemplate. You can move that out and put it on the page (by your popup div) and can simply call the Show() method.

页:

<asp:TemplateField>
  <ItemTemplate>
    <asp:LinkButton ID="LinkButton1" CommandName="Popup" runat="server">Popup</asp:LinkButton>
  </ItemTemplate>
</asp:TemplateField>

codebehind:

Codebehind:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Popup" && e.CommandArgument != null)
        {
            int rowIndex = Convert.ToInt32(e.CommandArgument);
            ModalPopupExtender1.Show();                

            //Perform any specific processing
            Label1.Text = string.Format("<Br>Row # {0}", rowIndex);
        }
    }

谢谢,祝你好运!

Thanks, good luck!

这篇关于ModalPopupExtender里面一个GridView的ItemTemplate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆