【问题标题】:Issue with modal pop up and download in gridview在gridview中弹出和下载模式的问题
【发布时间】:2012-02-02 14:52:50
【问题描述】:

我有一个包含以下文件的网格视图

附件(链接按钮)和评论(链接按钮)

当我点击附件时,我想下载文件,当我点击评论时,我想在弹出窗口中显示评论。为此,我使用了模态弹出窗口。

但是根据我编写的代码,这两者都适用于稍后在页面加载时的第一次尝试,或者不工作如何解决这个问题..

我的网格设计如下

<asp:GridView ID="grdAttaches_Client" runat="server" AutoGenerateColumns="false"
    CssClass="GridViewStyle" Width="585px" OnRowCommand="grdAttaches_Client_RowCommand"
    OnRowDataBound="grdAttaches_Client_RowDataBound">
    <Columns>
        <asp:TemplateField HeaderText="Attachment Name">
            <ItemTemplate>
                <asp:LinkButton ID="lblAttachmentName" Text='<%#Eval("AttachmentName")%>' runat="server" CommandName='Attachement' CommandArgument='<%# ((GridViewRow) Container).RowIndex %>' />
                <asp:Label ID="lblAttachmentid" runat="server" Visible="false" Text='<%#Eval("Attachmentid")%>'></asp:Label>
            </ItemTemplate>
            <ItemStyle CssClass="grid-left-txt2" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText=" Comment">
            <ItemTemplate>
                <asp:LinkButton ID="LinkButtonEdit" CommandName="ShowPopup" OnClick="lnkcommentsClick" runat="server"
                    Text='<%# Eval("Comments").ToString().Substring(0, Math.Min(Eval("Comments").ToString().Length, 10)) %>' CommandArgument='<%# ((GridViewRow) Container).RowIndex %>' > </asp:LinkButton>
                <asp:Label ID="lblComments1" runat="server" Visible="false" Text='<%#Eval("Comments")%>'></asp:Label>
            </ItemTemplate>
            <ItemStyle CssClass="grid-left-txt2" />
        </asp:TemplateField>
    </Columns>
    <RowStyle CssClass="RowStyle" />
    <EmptyDataRowStyle CssClass="EmptyRowStyle" />
    <PagerStyle CssClass="PagerStyle" />
    <HeaderStyle CssClass="HeaderStyle" />
    <EditRowStyle CssClass="EditRowStyle" />
    <AlternatingRowStyle CssClass="AltRowStyle" />
    <SelectedRowStyle CssClass="grid_data" />
    <PagerSettings Position="TopAndBottom" />
</asp:GridView>

在 Row 命令上我写如下

if (e.CommandName == "Click")
{
    GridViewRow gvRow = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
    LinkButton lbl_bs_id = (LinkButton)gvRow.FindControl("lnkcomments");
    //Response.Write(lbl_bs_id.Text);
    lnkcommentsClick(lbl_bs_id, EventArgs.Empty);
}
else
{
    string fname = e.CommandName.ToString();
    int aid = Convert.ToInt32(e.CommandArgument.ToString());
    FileDownload(fname, true, aid);
}

我的评论代码点击

protected void lnkcommentsClick(object sender, EventArgs e)
{
    LinkButton lnkdetails = sender as LinkButton;
    // lnkdetails=(LinkButton)e.fi
    GridViewRow gvrow = (GridViewRow)lnkdetails.NamingContainer;
    if (lnkdetails.Text != string.Empty)
    {
        lblPopUp.Text = lnkdetails.Text;
        mpeModalPopUp.Show();
    }
}

但我多次无法解决。加载页面后,我可以显示弹出窗口或文件下载。怎么做才能一直工作

【问题讨论】:

    标签: asp.net ajax gridview


    【解决方案1】:

    我重新创建了一个类似的场景来帮助你,都是 VB.Net 编码的。

    每当我执行回发或重新加载页面时,这都是有效的,这就是我对您说“多次”时的理解

    网格视图:

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
             <Columns>
            <asp:TemplateField HeaderText="Attachment Name">
                <ItemTemplate>
                    <asp:LinkButton ID="lblAttachmentName" Text='<%#Eval("AttachmentName")%>' runat="server" CommandName="Attachement" CommandArgument='<%# (CType(Container,GridViewRow)).RowIndex %>' />
                    <asp:Label ID="lblAttachmentid" runat="server" Visible="false" Text='<%#Eval("Attachmentid")%>'></asp:Label>
                </ItemTemplate>
                <ItemStyle CssClass="grid-left-txt2" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText=" Comment">
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButtonEdit" CommandName="ShowPopup" OnClick="lnkcommentsClick" runat="server"
                        Text='<%# Eval("Comments").ToString().Substring(0, Math.Min(Eval("Comments").ToString().Length, 10)) %>' CommandArgument='<%# (CType(Container,GridViewRow)).RowIndex %>' > </asp:LinkButton>
                    <asp:Label ID="lblComments1" runat="server" Visible="false" Text='<%#Eval("Comments")%>'></asp:Label>
                </ItemTemplate>
                <ItemStyle CssClass="grid-left-txt2" />
            </asp:TemplateField>
        </Columns>
            </asp:GridView>
    

    页面代码隐藏:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
            Dim grdPosts As New Posts()
    
            Dim post1 As New Post()
            post1.Comments = "Comment1"
            post1.AttachmentId = "1"
            post1.AttachmentName = "file1.jpg"
    
            Dim post2 As New Post()
            post1.AttachmentId = "2"
            post2.Comments = "Comment2"
            post2.AttachmentName = "file2.jpg"
    
            grdPosts.Add(post1)
            grdPosts.Add(post2)
    
            Me.GridView1.DataSource = grdPosts
            Me.GridView1.DataBind()
    
    
        End Sub
    
        Protected Sub lnkcommentsClick(ByVal sender As Object, ByVal e As System.EventArgs)
    
            Dim lnkdetails As LinkButton = TryCast(sender, LinkButton)
            MsgBox("LinkDetailsText: " & lnkdetails.Text)
    
        End Sub
    
        Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
    
            If e.CommandName = "Attachement" Then
    
                Dim fname As String = e.CommandName.ToString()
                Dim aid As Integer = Convert.ToInt32(e.CommandArgument.ToString())
                MsgBox("fname: " & fname & Boolean.TrueString & " iad: " & aid)
    
            End If
    
        End Sub
    

    由于这是有效的,问题可能与 lnkcmetsClick 和 FileDownload 方法的实现有关吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      • 2014-10-04
      • 1970-01-01
      • 1970-01-01
      • 2018-05-12
      • 2023-03-28
      相关资源
      最近更新 更多