gridview不会显示图像,而是显示文本"System.Byte []". [英] gridview, doesn't show me the image instead of showing me a text "System.Byte[]"

查看:72
本文介绍了gridview不会显示图像,而是显示文本"System.Byte []".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将gridview与objectdatasource一起使用以从sql数据库获取图像.在数据库中,数据字段被声明为"varbinary"数据类型.

现在在我的gridview中,它不会显示图像,而是显示文本"System.Byte []"

I try to use gridview with objectdatasource to obtain the images from the sql database. Within the database, a datafield is declare as "varbinary" datatype.

Now in my gridview, it doesn''t show me the image instead of showing me a text "System.Byte[]"

May I know how to solve it.

推荐答案

您必须将图像数据的byte []数组转换为图像,然后将其显示为网格视图

在gridviews行数据绑定事件中,您必须为此编写代码
You have to convert your byte[] array of image data to image and then show it to grid view

in gridviews row data bound event you have to write your code for this


您使用此代码,我正在使用此代码....将图像存储在数据库中后,您将使用此代码. .

Aspx页面...

You use this code, I was use this its work....After image stored in database you use this...

Aspx Page...

<p style="margin-left: 160px">
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

                DataKeyNames="inum" DataSourceID="SqlDataSource1" CellPadding="4"

                ForeColor="#333333" GridLines="None">
                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                <Columns>
                    <asp:BoundField DataField="inum" HeaderText="inum" InsertVisible="False" ReadOnly="True"

                        SortExpression="inum" />
                    <asp:BoundField DataField="iname" HeaderText="iname" SortExpression="iname" />
                    <asp:TemplateField HeaderText="image">
                    <ItemTemplate>

<asp:image ID="image1" runat="server"

ImageUrl='<%# "Handler.ashx?inum=" + Eval("inum")%>'/>
</ItemTemplate>
</asp:TemplateField>

                </Columns>
                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <EditRowStyle BackColor="#999999" />
                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
            </asp:GridView>

            <asp:SqlDataSource ID="SqlDataSource1" runat="server"

                ConnectionString="<%


ConnectionStrings:SomeDataBase1 %> " SelectCommand 选择inum,iname,FROM英尺的图像" 冲突检测 CompareAllValues" DeleteCommand 从[ft]处删除[inum] = @original_inum AND(([[iname] = @original_iname)或([iname]是NULL AND @ original_iname IS NULL))AND(([[image] = @original_image)OR([[image] IS NULL AND @original_image IS NULL)))" InsertCommand 插入INTO [ft]([inum],[iname],[image])值(@ inum,@ iname,@ image)" OldValuesParameterFormatString 原始文件{0}" UpdateCommand 更新[ft]设置[iname] = @iname,[image] = @image WHERE [inum] = @original_inum AND(([[iname] = @original_iname)OR([[iname]为NULL AND @original_iname为NULL))AND(([[image] = @original_image)OR([[image]为NULL AND @original_image为NULL)))" > < DeleteParameters > < asp:Parameter 名称 =" 类型 字符串" / < asp:Parameter 名称 =" 类型 字符串" / < asp:Parameter 名称 =" 类型 对象" / < /DeleteParameters > < UpdateParameters > < asp:Parameter 名称 =" 类型 字符串" / < asp:Parameter 名称 =" 类型 对象" / < asp:Parameter 名称 =" 类型 字符串" / < asp:Parameter 名称 =" 类型 字符串" / < asp:Parameter 名称 =" 类型 对象" / < /UpdateParameters > < InsertParameters > < asp:Parameter 名称 =" 类型 字符串" / < asp:Parameter 名称 =" 类型 字符串" / < asp:Parameter 名称 =" 类型 对象" / < /InsertParameters > < /asp:SqlDataSource >
ConnectionStrings:SomeDataBase1 %>" SelectCommand="SELECT inum, iname, image FROM ft" ConflictDetection="CompareAllValues" DeleteCommand="DELETE FROM [ft] WHERE [inum] = @original_inum AND (([iname] = @original_iname) OR ([iname] IS NULL AND @original_iname IS NULL)) AND (([image] = @original_image) OR ([image] IS NULL AND @original_image IS NULL))" InsertCommand="INSERT INTO [ft] ([inum], [iname], [image]) VALUES (@inum, @iname, @image)" OldValuesParameterFormatString="original_{0}" UpdateCommand="UPDATE [ft] SET [iname] = @iname, [image] = @image WHERE [inum] = @original_inum AND (([iname] = @original_iname) OR ([iname] IS NULL AND @original_iname IS NULL)) AND (([image] = @original_image) OR ([image] IS NULL AND @original_image IS NULL))"> <DeleteParameters> <asp:Parameter Name="original_inum" Type="String" /> <asp:Parameter Name="original_iname" Type="String" /> <asp:Parameter Name="original_image" Type="Object" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="iname" Type="String" /> <asp:Parameter Name="image" Type="Object" /> <asp:Parameter Name="original_inum" Type="String" /> <asp:Parameter Name="original_iname" Type="String" /> <asp:Parameter Name="original_image" Type="Object" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="inum" Type="String" /> <asp:Parameter Name="iname" Type="String" /> <asp:Parameter Name="image" Type="Object" /> </InsertParameters> </asp:SqlDataSource>




背后的代码...




Code Behind...

protected void Page_Load(object sender, EventArgs e)
       {
           SqlConnection con = new SqlConnection();
           string constr = ConfigurationManager.ConnectionStrings["SomeDataBase1"].ToString();
           con = new SqlConnection(constr);
           SqlCommand cmd = new SqlCommand();
           con.Open();

               GridView1.DataBind();
               con.Close();

       }


这篇关于gridview不会显示图像,而是显示文本"System.Byte []".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆