2012-02-02 19 views
1

我有以下的Fileds問題與模態彈出和下載的GridView

附件(鏈接按鈕)和評論(鏈接按鈕)

當我在附件點擊我想網格視圖下載文件,當我點擊評論我想在彈出窗口中顯示評論。爲此,我使用了模態彈出窗口。

但按代碼我寫了這個既適用於在頁面加載後在兩個或不工作怎麼解決這個第一次嘗試..

我的網格設計如下

<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> 

在命令行我寫如下

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

我種類的重新創建了一個類似的方案來試圖幫助你,都是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方法?