Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have gv as follows:
[IMG]http://i971.photobucket.com/albums/ae198/haocaocu/Errors/gv_zps075tlshr.png[/IMG]
code page aspx:
ASP.NET
<asp:GridView ID="grvDanhSach" AutoGenerateColumns="False" SkinID="SkinDefault" OnRowDataBound="grvDanhSach_RowDataBound"
                               BorderStyle="None" BorderWidth="1px" Width="100%" runat="server">
                               <Columns>
                                   <asp:TemplateField HeaderText="idCV" SortExpression="idCV" Visible="False">
                                       <ItemTemplate>
                                           <asp:Label ID="lblidCV" runat="server" Text='<%# Bind("idCV") %>'></asp:Label>
                                       </ItemTemplate>
                                   </asp:TemplateField>
                                   <asp:TemplateField HeaderText="Số công văn" SortExpression="SoCV">
                                       <ItemTemplate>
                                           <asp:LinkButton ID="lbtSoCV" Text='<%# Bind("SoCV") %>'
                                               CommandArgument='<%#Eval("FileToanVan")%>' OnClick="OpenPDF" runat="server" />
                                       </ItemTemplate>
                                       <HeaderStyle Width="150px" />
                                   </asp:TemplateField>
                                   <asp:BoundField DataField="RowNum" HeaderText="RowNum" SortExpression="RowNum" Visible="false" />
                                   <asp:BoundField DataField="FileToanVan" HeaderText="FileToanVan" SortExpression="FileToanVan"
                                       Visible="false" />
                                   <asp:BoundField DataField="TrichYeu" HeaderText="Trích yếu" SortExpression="TrichYeu" />
                                   <asp:BoundField DataField="DonViThucHien" HeaderStyle-Width="200px" HeaderText="Đơn vị thực hiện"
                                       SortExpression="DonViThucHien" />
                                   <asp:BoundField DataField="NgayNhan" HeaderText="Ngày nhận" SortExpression="NgayNhan"
                                       DataFormatString="{0:dd/MM/yyyy}">
                                       <HeaderStyle Width="80px" />
                                   </asp:BoundField>
                                   <asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="Đánh dấu">
                                       <ItemTemplate>
                                           <asp:LinkButton ID="lbtMark" runat="server"><img src="../images/mark-task.png" alt="" style="border:0;" /></asp:LinkButton>
                                       </ItemTemplate>
                                       <HeaderStyle Width="70px" />
                                       <ItemStyle HorizontalAlign="Center" />
                                   </asp:TemplateField>
                                   <asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="Giao việc">
                                       <ItemTemplate>
                                           <asp:LinkButton ID="lbtGiaoViec" runat="server" OnClick="lbtGiaoViec_Click"><img src="../images/change_process.png" alt="" style="border:0;" /></asp:LinkButton>
                                       </ItemTemplate>
                                       <HeaderStyle Width="60px" />
                                       <ItemStyle HorizontalAlign="Center" />
                                   </asp:TemplateField>
                                   <asp:TemplateField HeaderText="TrangThai" SortExpression="TrangThai" Visible="False">
                                       <ItemTemplate>
                                           <asp:Label ID="lblTrangThai" runat="server" Text='<%# Bind("TrangThai") %>'></asp:Label>
                                       </ItemTemplate>
                                   </asp:TemplateField>
                               </Columns>
                           </asp:GridView>

code c#:
C#
protected void grvDanhSach_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        try
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Services.cTB_CongVan mCongVan = new Services.cTB_CongVan();
                Services.cTB_User mUser = new Services.cTB_User();
                string strSoCV = "", strKhoangTrang = "";
                strKhoangTrang = "  ";
                DataSet ds = mCongVan.CongVan_SelectbyUserName(hidUserID.Value, "", "", cboLoaiCV.SelectedValue, "", "", currPage, 10, 5);
                DataTable dtb = ds.Tables[0];
                Label lblTrangThai = (Label)e.Row.FindControl("lblTrangThai");
                LinkButton lbtSoCV = (LinkButton)e.Row.FindControl("lbtSoCV");
                Label lblidCV=(Label)e.Row.FindControl("lblidCV");
                if (mCongVan.CongVan_DocHayChua(hidUserID.Value, int.Parse("0" + lblidCV.Text)) == 1)
                {
                    strSoCV = lbtSoCV.Text + strKhoangTrang;
                    lbtSoCV.Text = strSoCV;
                }
                else
                {
                    strSoCV = lbtSoCV.Text + strKhoangTrang + "<img src=\"../images/new.gif\" border=\"0\" /> ";
                    lbtSoCV.Text = strSoCV;
                }
                dtb.Dispose();
                mUser = null;
                mCongVan = null;
            }
        }
        catch
        { }
    }

C#
protected void OpenPDF(object sender, EventArgs e)
    {
        Services.cTB_CongVan mCongVan = new Services.cTB_CongVan();
        GridViewRow clickedRow = ((LinkButton)sender).NamingContainer as GridViewRow;
        Label lblidCV = (Label)clickedRow.FindControl("lblidCV");
        LinkButton lnkView = sender as LinkButton;
        string urlName = Request.Url.AbsoluteUri;
        // Removing the Page Name
        urlName = urlName.Remove(urlName.LastIndexOf("/")-5);
        //Adding FolderName and FileName in the URL
        string url = string.Format("{0}/Store/{1}", urlName, lnkView.CommandArgument.ToString());
        string script = "<script type='text/javascript'>window.open('" + url + "')</script>";
        this.ClientScript.RegisterStartupScript(this.GetType(), "script", script);
       
        mCongVan.UserDocCV_Edit(1, hidUserID.Value, int.Parse("0" + lblidCV.Text), 1);
        /*
        Services.cTB_CongVan mCongVan = new Services.cTB_CongVan();
        GridViewRow clickedRow = ((LinkButton)sender).NamingContainer as GridViewRow;
        Label lblidCV = (Label)clickedRow.FindControl("lblidCV");
        mCongVan.UserDocCV_Edit(1, hidUserID.Value, int.Parse("0" + lblidCV.Text), 1);
         
        LinkButton lnk = (LinkButton)sender;
        if (lnk != null)
        {
            Response.AddHeader("content-disposition", "attachment; filename=" + lnk.CommandArgument);
            Response.WriteFile(Server.MapPath("~/Store/" + lnk.CommandArgument.ToString()));
            Response.End();
        }
        */
         
        mCongVan = null;
         
    }

I use grvDanhSach_RowDataBound() to load data and insert image "New" for data row that have not been read.

When click the data row, i use OpenPDF() to open pdf content and remove the image "New", but the image doesn't remove until I reload page.

I want a solution that remove image "New" when i click the data using funtion OpenPDF().

Thanks.
Posted
Comments
haocaocu 25-Sep-15 3:19am    
With this code, I open the PDF in a new window but no page refresh is mother.
If I add the following code at the end of OpenPDF method it refreshes but does not open the pdf file
Response.Redirect(Request.Url.AbsoluteUri);
You help me with. Thank you!
Sinisa Hajnal 25-Sep-15 5:18am    
Add small javascript that will remove the new image on OpenPDF click
haocaocu 25-Sep-15 5:37am    
You can only be non-specific
Sinisa Hajnal 25-Sep-15 6:06am    
I was non-specific :)

But seriously, if you will be doing web development, learn the basics.
In this case, write onclik="myClickHandler();"
<script type="text/javascript">
function myClickHandler() { document.getElementById(your_id).hide(); }
(or maybe its .visible = false instead of hide? Easily found...
haocaocu 28-Sep-15 3:56am    
Hi Sinisa Hajnal
I used the following code to check:
if (mCongVan.CongVan_DocHayChua(hidUserID.Value, int.Parse("0" + lblidCV.Text)) == 1)
{
strSoCV = lbtSoCV.Text + strKhoangTrang;
lbtSoCV.Text = strSoCV;
}
else
{
strSoCV = lbtSoCV.Text + strKhoangTrang + "<img src=\"../images/new.gif\" border=\"0\" /> ";
lbtSoCV.Text = strSoCV;
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900