ALGrid may works with images stored in database - edit, upload and delete them.
To work with images:
- Create table in database which will contains images, then create field of type Image (for SQL Server 2000) or varbinary(MAX) (for SQL Server 2005 or SQL Server 2005 Express Edition)
- Create SQL datasource control on the page and attach it to the database table, which contains images.
Modify code of the datasource for correct working with images.
For SQL Server 2005 or SQL Server 2005 Express Edition:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<$ ConnectionStrings>"
DeleteCommand="DELETE FROM [Images] WHERE [id] = @id"
InsertCommand="INSERT INTO [Images] ([image1], [image2]) VALUES (CONVERT(image, @image1), CONVERT(image, @image2))"
SelectCommand="SELECT [id], [image1], [image2] FROM [Images]"
UpdateCommand="UPDATE [Images] SET [image1] = CONVERT(image, @image1), [image2] = CONVERT(image, @image2) WHERE [id] = @id"
OnInserting="SqlDataSource1_Inserting" >
<DeleteParameters>
<asp:Parameter Name="id" Type="Object" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="image1" Type="Object" />
<asp:Parameter Name="image2" Type="Object" />
<asp:Parameter Name="id" Type="Object" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="image1" Type="Object" />
<asp:Parameter Name="image2" Type="Object" />
</InsertParameters>
</asp:SqlDataSource>
Attach Inserting event handler for the datasource:
protected void SqlDataSource1_Inserting(object sender, SqlDataSourceCommandEventArgs e)
{
foreach (SqlParameter parameter in e.Command.Parameters)
{
if (parameter.DbType == DbType.Object)
parameter.SqlDbType = SqlDbType.Image;
}
}
This is for inserting byte array as images into database.
- Create ALGrid control on the page and associate it with SQL datasource.
<al:ALGrid ID="ALGrid1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="False" DataKeyNames="id">
<Columns>
<al:TextBoxField DataField="id" HeaderText="id" InsertVisible="False" SortExpression="id" Visible="False" />
<al:BinaryImageField DataField="image1" HeaderText="Image" SortExpression="image1" />
<al:BinaryImageField DataField="image2" HeaderText="Image 2" SortExpression="image2" />
<al:ALCommandField ShowDeleteButton="True" ShowEditButton="True" />
</Columns>
</al:ALGrid>
Call "Edit columns..." command from context menu for ALGrid.

"Columns" dialog appears.
Drag images fields from "Available" list to "Columns" list.

Set type of images columns to BinaryImageField from "Convert to" list.

- In run-time appears ALGrid with two images columns. To add new images into database call "New" command. To edit images - call "Edit" command.
Controls: ALGrid
ALGrid: Column Types | Paging | Filtering | Preview Row
© 2002-2007 Astron Digital. All Rights Reserved.