Click here to Skip to main content
15,907,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when user upload any document then this document go for approval when this document approve then user able to download to download other vise not

this is want i done

SQL
  doc id doc name file uplaoded uploaded date department status
 1    analysis  abc.docx    12-12-2013   finance        approve  downlaod
  2     abdcr  hr.docx    14-06-2013   finance       reject      downlaod
3    dff      r.docx    14-06-2013   finance         approve      downlaod
4    rdfdfhr  hdfr.docx    14-06-2013   finance         reject   downlaod

and this is what i want

C#
doc id doc name file uplaoded uploaded date department status
  1    analysis  abc.docx    12-12-2013   finance        approve   download
   2     abdcr  hr.docx    14-06-2013   finance       reject
  3    dff      r.docx    14-06-2013   finance         approve      downlaod
 4    rdfdfhr  hdfr.docx    14-06-2013   finance         reject

now in reject row i don't want to show download option because this is rejected documents here is download code



C#
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "download")
        {
            string filename = e.CommandArgument.ToString();
            string path = MapPath("~/Docfiles/" + filename);
            byte[] bts = System.IO.File.ReadAllBytes(path);
            Response.Clear();
            Response.ClearHeaders();
            Response.AddHeader("Content-Type", "Application/octet-stream");
            Response.AddHeader("Content-Length", bts.Length.ToString());
            Response.AddHeader("Content-Disposition", "attachment; filename=" + 
            filename);
            Response.BinaryWrite(bts);
            Response.Flush();
            Response.End();
        }


    }

I try this in item bound but it not work

C#
protected void Repeater4_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            //DataRowView theDataRowView = e.Item.DataItem as DataRowView;
            //theDataRowView.Row["Status"] == "Status";

            // Only look in data rows, ignore header and footer rows
            if (e.Item.ItemType == ListItemType.AlternatingItem ||
           e.Item.ItemType == ListItemType.Item)
            {
                // Get a data view row object so we can reference the data
                // in the repeater by the bound field names
                DataRowView theDataRowView = e.Item.DataItem as DataRowView;
                //theDataRowView.Row["Status"] == "Status";

                // Make sure we got the data row view before we try to use it
                if (theDataRowView != null)
                {
                    // Get the value of status from the control that holds the value
                    string theStatus = theDataRowView.Row["Status"].ToString();

                    // Find the download link control
                    LinkButton theLinkButtonDownload = e.Item.FindControl("LinkButton1") as LinkButton;

                    if (theStatus.ToLower() == "APPROVE")
                    {
                        if (theLinkButtonDownload != null)
                        {
                            theLinkButtonDownload.Visible = true;
                        }
                    }
                    else
                    {
                        if (theLinkButtonDownload != null)
                        {
                            theLinkButtonDownload.Visible = false;
                        }
                    }
                }
            }
        }



any help?
Posted
Updated 27-Nov-13 9:23am
v3
Comments
JoCodes 27-Nov-13 23:07pm    
tried debugging the code? Is it entering into the if else block which makes visible true/false?
Naresh Pansuriya 28-Nov-13 2:32am    
have you used undate panel?

1 solution

Try using as below

protected void Repeater4_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {         

            if (e.Item.ItemType == ListItemType.AlternatingItem ||
           e.Item.ItemType == ListItemType.Item)
            {
                Label lblStatus = ( Label ) e.Item.FindControl ( "lblStatus" );//Change label to other controls like literal as per you are using                     

                    // Find the download link control
                    LinkButton theLinkButtonDownload = e.Item.FindControl("LinkButton1") as LinkButton;
 
   if ( lblStatus .Text.Trim ( ) == "APPROVE" )//Use String.Compare with ordinal case to check case sensitiveness instead of == operator  
                    {
                        if (theLinkButtonDownload != null)
                        {
                            theLinkButtonDownload.Visible = true;
                        }
                    }
                    else
                    {
                        if (theLinkButtonDownload != null)
                        {
                            theLinkButtonDownload.Visible = false;
                        }
                    }
                }
            }
 
Share this answer
 
Comments
Diya Ayesa 28-Nov-13 1:30am    
i try this but now work it is always visible in reject
code
protected void Repeater4_ItemDataBound(object sender, RepeaterItemEventArgs e)
{




if (e.Item.ItemType == ListItemType.AlternatingItem ||
e.Item.ItemType == ListItemType.Item)
{
Label lblStatus = (Label)e.Item.FindControl("HiddenField1");//Change label to other controls like literal as per you are using

// Find the download link control
LinkButton theLinkButtonDownload = e.Item.FindControl("LinkButton2") as LinkButton;

if (lblStatus.Text.Trim() == "APPROVE")//Use String.Compare with ordinal case to check case sensitiveness instead of == operator
{
if (theLinkButtonDownload != null)
{
theLinkButtonDownload.Visible = true;
}
}
else
{
if (theLinkButtonDownload != null)
{
theLinkButtonDownload.Visible = false;
}
}
}
Diya Ayesa 28-Nov-13 1:33am    
html

<div class="CSSTableGenerator">
<table border="0" width="100%" cellpadding="0" cellspacing="0" id="results">
<asp:Repeater ID="Repeater4" OnItemCommand="Repeater4_ItemCommand" runat="server">
<HeaderTemplate>
<tr>
<td>
</td>

<td>
</td>
<td>
Document ID
</td>
<td>
Document Name
</td>
<td>
File Uploaded
</td>
<td>
Uploaded By
</td>
<td>
Document Type
</td>
<td>
Department Type
</td>
<td>
Approve Name
</td>
</tr>
</HeaderTemplate>
<itemtemplate>
<tr>
<td>

<asp:HiddenField ID="HiddenField1" runat="server" Value='<%#DataBinder.Eval(Container.DataItem, "Status")%>'/>

</td>
<td>
<asp:LinkButton ID="LinkButton2" runat="server" CommandArgument='<%# Eval("FileUploaded") %>'
CommandName="download" Visible='<%# Convert.ToString(Eval("Status")).ToUpper() != "Reject" %>' Text="Download" />


</td>


<%-- <td>
<asp:LinkButton ID="LinkButton1" runat="server" CommandArgument='<%# Eval("FileUploaded") %>'
CommandName="download" >Download
</td>--%>
<td>
<%#DataBinder.Eval(Container.DataItem,"DocumentID") %>
</td>
<td>
<%#DataBinder.Eval(Container.DataItem, "DocumentName")%>
</td>
<td>
<%#DataBinder.Eval(Container.DataItem, "FileUploaded")%>
</td>
<td>
<%#DataBinder.Eval(Container.DataItem, "UploadedBy")%>
</td>
<td>
<%#DataBinder.Eval(Container.DataItem, "Document")%>
</td>
<td>
<%#DataBinder.Eval(Container.DataItem, "Department")%>
</td>
<td>
JoCodes 28-Nov-13 1:46am    
R u trying to set the visible false in client side too? in that case dont use string.upper() . use string.compare like <%# String.Compare(Convert.ToString(Eval("Status")),"Reject",true)!=0 %>
JoCodes 28-Nov-13 1:51am    
If you are trying to do it in design markup then no need to do the same in codebehind

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