0

我有一个带有以下标记的详细视图,此详细视图的数据源来自存储过程“spDocResult”,如下所示:

select DocId,TransId,FileId,Filename,ContentType,Data,DocumentNo,Title,TRANSMITTAL
from DocumentSum2
where (DocId=@Docid)AND(Transid=@Transid)

此详细视图的一个字段应显示 Efile Names,因此我为此设置了 1 个用户控件

public partial class FileTemp : System.Web.UI.UserControl
{
    private EDMSDataContext _DataContext;
private IEnumerable<tblFile> _Efiles;

public IEnumerable<tblFile> Efiles
{
    set { _Efiles = value; }
}
protected void Page_Load(object sender, EventArgs e)
{ 
}
    protected void LinkButton1_Command(object sender, CommandEventArgs e)
{
    if (e.CommandName == "Download")
    {
         _DataContext = new EDMSDataContext();
        //you can get your command argument values as follows
        string FileId = e.CommandArgument.ToString();
       int _FileId = Convert.ToInt32(FileId);
       tblFile Efile = (from ef in _DataContext.tblFiles
                    where ef.FileId == _FileId
                    select ef).Single();
       if (Efile != null)
       {

           download(Efile);

       }}}

        private void download ( tblFile Efile)

{

Byte[] bytes = (Byte[])Efile.Data.ToArray();
Response.Clear();

Response.Buffer = true;

Response.Charset = "";

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.ContentType = Efile.ContentType.ToString();

Response.AddHeader("content-disposition", "attachment;filename="

+ Efile.FileName.ToString());

Response.BinaryWrite(bytes);

Response.Flush();

Response.End();

}

public override void DataBind()
        {
            base.DataBind();
            GridViewEfile.DataSource = _Efiles;
            GridViewEfile.DataBind();

        }

}

现在我有问题,因为 detailview 的数据源来自存储过程,而用户控件的属性来自 tblFile,所以当我使用 DetailsView1_DataBound 时,我不知道如何获取用户控件属性。当我使用下面的代码时,我有错误

can not implicity convert type string to system.collection.generic.iEnumerable<tblfile>

我对这条线有错误

fileList.Efiles = docresult.Filename;

protected void DetailsView1_DataBound(object sender, EventArgs e)
{

    spDocResultResult docresult = (spDocResultResult)DetailsView1.DataItem;
    FileTemp fileList = (FileTemp)DetailsView1.FindControl("FileTemp1");

    fileList.Efiles = docresult.Filename;
    fileList.DataBind();
}
4

1 回答 1

1

这可能根本不是数据绑定问题。从上下文中收集起来有点困难,但是......

FileTemp fileList = (FileTemp)DetailsView1.FindControl("FileTemp1");    
fileList.Efiles = docresult.Filename;

fileList.Efiles 是您只想为其分配文件名的项目列表吗?如果是这样,您可能只需要遍历它们。

foreach (var file in fileList.Efiles)
{
    file.FileName = docresult.Filename;
}

此外,将此行添加到您的 Efiles 声明以解决 Get 访问器错误。

public IEnumerable<tblFile> Efiles
{
    get { return _Efiles; } // <- here
    set { _Efiles = value; }
}
于 2012-11-16T16:46:20.977 回答