Click here to Skip to main content
15,920,468 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a page which uploads the image by fileuploader to the database and displays the list of all the images in the same page in grid view.
I am not able to view the images but the rest of details like imageid, name are displayed. Have a look into the aspx below and let me know where i went wrong, its urgent...
.aspx
XML
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Item Name"></asp:Label>
<asp:TextBox ID="itmname" runat="server" Width="125px"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Text="Description"></asp:Label>
<asp:TextBox ID="description" runat="server" Width="128px"></asp:TextBox>
<asp:Label ID="Label3" runat="server" Text="Image for Item"></asp:Label>
<asp:FileUpload ID="FileUpload1" runat="server" Height="21px" Width="211px" />
<asp:Button ID="Upload" runat="server" onclick="Upload_Click" Text="Upload" />
<asp:Button ID="delete_button" runat="server"
Text="Delete" />
</table>
<asp:Label ID="lblMessage" runat="server"></asp:Label>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" Width="213px" DataKeyNames="Item_Id"
AllowPaging="True" AllowSorting="True" BackColor="White" BorderColor="#CC9966"
BorderStyle="None" BorderWidth="1px" CellPadding="4">
<RowStyle BackColor="White" ForeColor="#330099" />
<Columns>
<asp:CommandField
ShowSelectButton="True" />
<asp:BoundField DataField="Item_Id" HeaderText="Item_Id"
InsertVisible="False" ReadOnly="True"
SortExpression="Item_Id" />
<asp:BoundField DataField="Item_name" HeaderText="Item_name"
SortExpression="Item_name" />
<asp:BoundField DataField="descriptions" HeaderText="descriptions"
SortExpression="descriptions" />
<asp:TemplateField HeaderText="Image">
<ItemTemplate>
<asp:Image ID="Image1" runat="server"
ImageUrl='<%# "Handler2.ashx?Item_Id=" + Eval("Item_Id")%>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:setting %>"
SelectCommand="SELECT [Item_Id], [Item_name], [descriptions], [Images] FROM [items]"
ConflictDetection="CompareAllValues"
DeleteCommand="DELETE FROM [items] WHERE [Item_Id] = @original_Item_Id AND [Item_name] = @original_Item_name AND (([descriptions] = @original_description) OR ([descriptions] IS NULL AND @original_description IS NULL)) AND (([Image] = @original_Image) OR ([Images] IS NULL AND @original_Image IS NULL))"
InsertCommand="INSERT INTO [items] ([Item_name], [descriptions], [Images]) VALUES (@Item_name, @description, @Image)"
OldValuesParameterFormatString="original_{0}"
UpdateCommand="UPDATE [items] SET [Item_name] = @Item_name, [descriptions] = @description, [Images] = @Image WHERE [Item_Id] = @original_Item_Id AND [Item_name] = @original_Item_name AND (([descriptions] = @original_description) OR ([descriptions] IS NULL AND @original_description IS NULL)) AND (([Images] = @original_Image) OR ([Images] IS NULL AND @original_Image IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_Item_Id" Type="Decimal" />
<asp:Parameter Name="original_Item_name" Type="String" />
<asp:Parameter Name="original_description" Type="String" />
<asp:Parameter Name="original_Image" Type="Object" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Item_name" Type="String" />
<asp:Parameter Name="descriptions" Type="String" />
<asp:Parameter Name="Images" Type="Object" />
<asp:Parameter Name="original_Item_Id" Type="Decimal" />
<asp:Parameter Name="original_Item_name" Type="String" />
<asp:Parameter Name="original_description" Type="String" />
<asp:Parameter Name="original_Image" Type="Object" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="Item_name" Type="String" />
<asp:Parameter Name="descriptions" Type="String" />
<asp:Parameter Name="Images" Type="Object" />
</InsertParameters>
</asp:SqlDataSource>
</div>
</form>


C#
Handler
SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["setting"].ConnectionString;
// Create SQL Command
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "Select Item_id,descriptions,Images from items where Item_Id =@Item_Id";
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = con;
SqlParameter ImageID = new SqlParameter("@Item_Id", System.Data.SqlDbType.Int);
ImageID.Value = context.Request.QueryString["Item_Id"];
cmd.Parameters.Add(ImageID);
con.Open();
SqlDataReader dReader = cmd.ExecuteReader();
dReader.Read();
context.Response.BinaryWrite((byte[])dReader["Images"]);
dReader.Close();
con.Close();


I am able to view all details except the image from database, I also checked the image binary as well when inserting in database...
Thanks,
Sathish kumar S
Play with codings...
Posted
Updated 19-Dec-10 18:04pm
v3
Comments
thatraja 20-Dec-10 0:04am    
what's the error message?Include that in your question.
Sandeep Mewara 20-Dec-10 0:50am    
Looks like an issue with the way image is being tried to be pulled out and displayed. Look at the exisitng articles/links doing the same.

1 solution

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