【发布时间】:2016-05-26 16:45:46
【问题描述】:
我在我的 asp 页面的 on-load() 函数上绑定了数据,我可以检索所有数据,但很遗憾我看不到图像。我附上了代码,请给我一些想法,我该怎么做?帮助我在网格视图中显示图像。
<asp:GridView ID="GridView2" runat="server">
<AlternatingRowStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="#C19E45" ForeColor="White" />
<SelectedRowStyle BackColor="#3333CC" ForeColor="Red" />
</asp:GridView>
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = client.viewClients();
DataTable newdt = new DataTable();//for filtering data
newdt.Columns.Add("id", typeof(string));
newdt.Columns.Add("Name", typeof(string));
newdt.Columns.Add("Father/Husband", typeof(string));
newdt.Columns.Add("Cnic", typeof(string));
newdt.Columns.Add("Occupation", typeof(string));
newdt.Columns.Add("Present_Address", typeof(string));
newdt.Columns.Add("Telephone", typeof(string));
newdt.Columns.Add("Phone", typeof(string));
newdt.Columns.Add("Email", typeof(string));
newdt.Columns.Add("Permanent_address", typeof(string));
newdt.Columns.Add("Nominee_name", typeof(string));
newdt.Columns.Add("Nominee_address", typeof(string));
newdt.Columns.Add("Nominee_cnic", typeof(string));
newdt.Columns.Add("nominee_no", typeof(string));
newdt.Columns.Add("Image", typeof(string));
newdt.Columns.Add("registeration_no", typeof(string));
foreach (DataRow row in dt.Rows)
{
DataRow nrow = newdt.NewRow(); //creating newRow
// byte[] imgarray = (byte[])row["image"];
// System.Drawing.Image img = client.byteArrayToImage(imgarray);
nrow["id"]=row["id"];
nrow["Name"] = row["name"];
nrow["Father/Husband"] = row["relation_of"];
nrow["Cnic"] = row["applicant_cnic"];
nrow["Occupation"] = row["occupation"];
nrow["Present_Address"] = row["present_address"];
nrow["Telephone"] = row["telephone"];
nrow["Phone"] = row["mobile"];
nrow["Email"] = row["email"];
nrow["Permanent_address"] = row["permanent_address"];
nrow["Nominee_name"] = row["nominee_name"];
nrow["Nominee_address"] = row["nominee_address"];
nrow["Nominee_cnic"] = row["nominee_cnic"];
nrow["nominee_no"] = row["nominee_no"];
nrow["Image"] = row["image"];
nrow["registeration_no"] = row["registeration_no"];
newdt.Rows.Add(nrow);
}
GridView2.DataSource = newdt;
GridView2.DataBind();
}
【问题讨论】: