如何在gridview中显示Byte []数据

时间:2013-03-10 16:47:19

标签: c# asp.net

要在Byte[]中显示GridView数据,我使用了以下代码

DataColumn dc4 = new DataColumn("Bytes", typeof(string));

我想知道它是否正确?

完整代码如下:

Stream fs = FileUpload1.PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);

Byte[] bytes = br.ReadBytes((Int32)fs.Length);

DataColumn dc4 = new DataColumn("Bytes", typeof(string));

dt = new DataTable();
DataColumn dc1 = new DataColumn("File Name", typeof(string));
DataColumn dc2 = 1new DataColumn("File Size", typeof(string));
DataColumn dc3 = new DataColumn("Content Type", typeof(string));
DataColumn dc4 = new DataColumn("Bytes", typeof(string));

dt.Columns.Add(dc1);
dt.Columns.Add(dc2);
dt.Columns.Add(dc3);
dt.Columns.Add(dc4);

dr = dt.NewRow();

dr["File Name"] = FileName;

if (size > 0)
  dr["File Size"] = size.ToString() + " KB";
else
  { dr["File Size"] = fileObj.Length.ToString() + " Bytes"; }

dr["Content Type"] = contenttype;
dr["Bytes"] = bytes;


dt.Rows.Add(dr);
GridViewEfile.DataSource = dt;
GridViewEfile.DataBind();

0 个答案:

没有答案