Hi, I'm new to ASP, I'm pretty good with Java, but am only just looking at C# and asp due to a uni assignment.
I have a problem accessing data in a Datalist, which is held in a cell of a DataTable.
It's a bit of a mess, but I want to access the contents of the ArrayList cell, bound to DataList dataList, specifically the filepath object, in the HTML.
Any ideas anybody? All help greatly appreciated
I have a problem accessing data in a Datalist, which is held in a cell of a DataTable.
Code:
public class GalleryGrid : System.Web.UI.Page
{
public int gridwidth = 4;
public int gridheight = 3;
ArrayList files = new ArrayList();
public DataTable getTable()
{
DataTable dt = new DataTable();
string colName;
files = getFiles();
for (int i = 0; i < gridwidth; i++)
{
colName = "gridImage"+i;
//myNewColumn.ColumnName = colName;
//DataColumn myNewColumn = new DataColumn();
//dt.Columns.Add(myNewColumn);
//dt.Columns[i].ColumnName = colName;
dt.Columns.Add(colName, typeof(string));
}
if (files != null)
{
for (int j = 0; j < gridheight; j++)
{
DataRow myNewRow;
myNewRow = dt.NewRow();
for (int i = 0; i < gridwidth; i++)
{
if ((i+(j*gridwidth)) < files.Count)
{
Thumbnail thumbnail = new Thumbnail();
string path = files[(i + (j * gridwidth))].ToString();
string filepath = "~/Images/Images/"+path;
System.Drawing.Image image = thumbnail.GetThumbnail(path);
int width = thumbnail.GetWidth();
int height = thumbnail.GetHeight();
ArrayList cell = new ArrayList();
cell.Insert(0, image);
cell.Insert(1, width);
cell.Insert(2, height);
cell.Insert(3, filepath);
DataList dataList = new DataList();
dataList.DataSource = cell;
dataList.DataBind();
myNewRow[i] = dataList;
Console.Write(files[(i + (j * gridwidth))]);
}
else
{
myNewRow[i] = "null";
}
}
dt.Rows.Add(myNewRow);
}
}
return dt;
}
public string ResolveUrl(string originalUrl)
{
if (!string.IsNullOrEmpty(originalUrl) && '~' == originalUrl[0])
{
int index = originalUrl.IndexOf('?');
string queryString = (-1 == index) ? null : originalUrl.Substring(index);
if (-1 != index) originalUrl = originalUrl.Substring(0, index);
originalUrl = VirtualPathUtility.ToAbsolute(originalUrl) + queryString;
}
return originalUrl;
}
public ArrayList getFiles()
{
int i = 1;
foreach (string file in Directory.GetFiles(System.Web.HttpContext.Current.Server.MapPath("Images") + "\\", "*.jpg"))
{
files.Add(Path.GetFileName(ResolveUrl(file)));//"ThumbnailCreator.aspx?ImageId=" +
i++;
}
return files;
}
Code:
<asp:GridView ID="DataGridView1" runat="server" AutoGenerateColumns="false"
AutoGenerateEditButton="false" CellPadding="4" AllowPaging="true"
onselectedindexchanged="DataGridView1_SelectedIndexChanged" EnableViewState="false" OnRowCommand="DataGridView1_RowCommand">
<Columns>
<asp:TemplateField HeaderText="gridImage0" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:ImageButton ID='Image0' runat='server' ImageURL='<%# DataBinder.Eval(Container.DataItem, "filepath")%>' OnClick='lblClick1' CommandName="picture" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "gridImage0")%>' ></asp:ImageButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="gridImage1" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:ImageButton ID='Image1' runat='server' ImageURL='<%# "Thumbnail.aspx?ImageId=" + DataBinder.Eval(Container.DataItem, "gridImage1")%>' OnClick='lblClick1' CommandName="picture" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "gridImage1")%>' ></asp:ImageButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="gridImage2" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:ImageButton ID='Image2' runat='server' ImageURL='<%# "Thumbnail.aspx?ImageId=" + DataBinder.Eval(Container.DataItem, "gridImage2")%>' OnClick='lblClick1' CommandName="picture" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "gridImage2")%>' ></asp:ImageButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="gridImage3" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:ImageButton ID='Image3' runat='server' ImageURL='<%# "Thumbnail.aspx?ImageId=" + DataBinder.Eval(Container.DataItem, "gridImage3")%>' OnClick='lblClick1' CommandName="picture" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "gridImage3")%>' ></asp:ImageButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
It's a bit of a mess, but I want to access the contents of the ArrayList cell, bound to DataList dataList, specifically the filepath object, in the HTML.
Any ideas anybody? All help greatly appreciated
Last edited: