Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 中继器表中的下载选项_C#_Asp.net - Fatal编程技术网

C# 中继器表中的下载选项

C# 中继器表中的下载选项,c#,asp.net,C#,Asp.net,当用户上载任何文档时,则此文档进行审批当此文档审批时,则用户可以下载以下载其他vise not 这是我想要做的 doc id doc name file uplaoded uploaded date department status download 1 analysis abc.docx 12-12-2013 finance approve download 2 report fm

当用户上载任何文档时,则此文档进行审批当此文档审批时,则用户可以下载以下载其他vise not

这是我想要做的

           doc id doc name file uplaoded uploaded date department       status 
   download       1    analysis  abc.docx    12-12-2013   finance        approve
   download      2    report fm  fm.docx    14-06-2013   finance         reject
  download      3    report ibf  ibf.docx    14-06-2013   finance         approve
   download      4    report ma  ma.docx    14-06-2013   finance         reject
这就是我想要的

            doc id doc name file uplaoded uploaded date department       status 
   download       1    analysis  abc.docx    12-12-2013   finance        approve
                 2    report fm  fm.docx    14-06-2013   finance         reject
  download       3    report ibf  ibf.docx    14-06-2013   finance         approve
                 4    report ma  ma.docx    14-06-2013   finance         reject
现在在拒绝行中,我不想显示下载选项,因为这是被拒绝的文档 这里是下载代码

  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();
        }


    }
html


文件ID
文件名
上传的文件
上载日期
文件类型
部门类型
名称核准
下载

我是如何做到这一点的?

由于您绑定到一个数据源,并且中继器的标记中没有用于要检查的文本的服务器控件,因此您需要在
ItemDataBound
事件中使用
DataRowView
对象,如下所示:

DataRowView theDataRowView = e.Item.DataItem as DataRowView;
theDataRowView.Row["Status"] == "some value"
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    // 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;

        // 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"];

            // 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;
                }
            }
        }
    }
}
现在,您可以通过标记中使用的绑定值引用数据,如下所示:

DataRowView theDataRowView = e.Item.DataItem as DataRowView;
theDataRowView.Row["Status"] == "some value"
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    // 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;

        // 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"];

            // 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;
                }
            }
        }
    }
}
因此,您的
ItemDataBound
事件现在应该如下所示:

DataRowView theDataRowView = e.Item.DataItem as DataRowView;
theDataRowView.Row["Status"] == "some value"
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    // 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;

        // 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"];

            // 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;
                }
            }
        }
    }
}

由于您要绑定到数据源,并且中继器的标记中没有用于要检查的文本的服务器控件,因此需要在
ItemDataBound
事件中使用
DataRowView
对象,如下所示:

DataRowView theDataRowView = e.Item.DataItem as DataRowView;
theDataRowView.Row["Status"] == "some value"
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    // 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;

        // 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"];

            // 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;
                }
            }
        }
    }
}
现在,您可以通过标记中使用的绑定值引用数据,如下所示:

DataRowView theDataRowView = e.Item.DataItem as DataRowView;
theDataRowView.Row["Status"] == "some value"
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    // 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;

        // 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"];

            // 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;
                }
            }
        }
    }
}
因此,您的
ItemDataBound
事件现在应该如下所示:

DataRowView theDataRowView = e.Item.DataItem as DataRowView;
theDataRowView.Row["Status"] == "some value"
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    // 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;

        // 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"];

            // 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;
                }
            }
        }
    }
}

这段代码是我在html或以上repeater1_itemdatabound中添加if(theDataRowView.Row[“Status”]=“Status”){}的代码,我在html或以上repeater1_itemdatabound中添加if(theDataRowView.Row[“Status”]=“Status”){}的代码databound@user2931015-我已经更新了答案,我通常是说如何使用
DataRowView.Row
对象。我在回答中发布的代码使用以下
if(theStatus.ToLower()=“approve”)
,其中
theStatus
是从
DataRowView
对象中检索的,如下所示:
string theStatus=theDataRowView.Row[“Status”]。很抱歉造成混淆。这段代码是我在html或以上repeater1_itemdatabound中添加if(theDataRowView.Row[“Status”]=“Status”){}的代码,我在html或以上repeater1_itemdatabound中添加if(theDataRowView.Row[“Status”]=“Status”){}的代码databound@user2931015-我已经更新了答案,我通常是说如何使用
DataRowView.Row
对象。我在回答中发布的代码使用以下
if(theStatus.ToLower()=“approve”)
,其中
theStatus
是从
DataRowView
对象中检索的,如下所示:
string theStatus=theDataRowView.Row[“Status”]。很抱歉给你带来了困惑。