【发布时间】: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();
}
}
但我多次无法解决。加载页面后,我可以显示弹出窗口或文件下载。怎么做才能一直工作
【问题讨论】: