我的网格视图包含以下文件
附件(链接按钮)和注释(链接按钮)
当我点击附件时,我想下载文件,当我点击评论时,我想在弹出窗口中显示评论。为此,我使用了模态弹出窗口。
但是根据我写的代码,这两个作品首次尝试在页面加载后两者或不工作如何解决这个问题。
我的网格设计如下
<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>
On 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();
}
}
但我无法多次解决这个问题。页面加载后,我可以显示弹出或文件下载。该怎么做才能一直工作
答案 0 :(得分:0)
我重新创建了一个类似的场景来试图帮助你,所有的VB.Net编码。
每次执行回发或重新加载页面时这都有效,这就是我所说的“多次”时的理解
的GridView:
<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
由于这个工作可能问题继续执行lnkcommentsClick和FileDownload方法?