Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello... my question is how to display image in image control and display details in gridview by using join two tables in asp.net and C#??

i have two tables which are barcode printer detail and image. i use join tables to display details and image. But i just can display image without details. Is it possible to display image in control? Below is my code:
C#
SqlDataAdapter SDA = new SqlDataAdapter("SELECT B.Product,B.Model,B.SerialNo,B.IT_Tag,B.PrinterID,B.Department,B.Location,L.Image FROM BarCodePrinter B JOIN Layout L ON L.Department=B.Department AND L.Location=B.Location WHERE B.SerialNo=@SN OR B.IT_Tag=@Tag OR B.PrinterID=@PrinterID", con);                 
                    SDA.SelectCommand.Parameters.AddWithValue("@SN", TextBox1.Text);
                    SDA.SelectCommand.Parameters.AddWithValue("@Tag", TextBox1.Text);
                    SDA.SelectCommand.Parameters.AddWithValue("@PrinterID", TextBox1.Text);
                    DataSet ds = new DataSet();
                    DataTable dt = new DataTable();
                    
                    SDA.Fill(dt);
     
                    //match with database
                    if (dt.Rows.Count > 0)
                    {
                        GridView3.DataSource = dt;
                        GridView3.DataBind();
                        GridView3.Focus();
                       Byte[] bytes = (Byte[])dt.Rows[0]["Image"];
                     Response.BinaryWrite(bytes);
                     Response.Flush();
                      Response.End();  
                       
                    } 

Please help me!!! thanks.
Posted
Updated 3-Jan-13 14:43pm
v3

1 solution

you can use Eval() method in aspx page for display detail.

Example : -
XML
<asp:GridView ID="GridView1" runat="server">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:Label ID="lblmodel" runat="server" Text='<%# Eval("Model") %>'></asp:Label>
                    <asp:Label ID="lblIT_Tag" runat="server" Text='<%# Eval("IT_Tag") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>




reply
 
Share this answer
 
Comments
WinnieMeeKun 3-Jan-13 19:50pm    
Hello..thanks for ur solution..but the Gridview3 is for display the details...but when run system, the details missing and only image display...y???
Rakesh Tailor 4-Jan-13 2:46am    
hello... can you display your database table..?
WinnieMeeKun 6-Jan-13 22:07pm    
hello!!! display database table??? i have two tables...so, i join the two tables to retrieve image and details...
Rakesh Tailor 4-Jan-13 3:07am    
hello.... once comment to
Response.End();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900