Imar,
I've got a small problem, How could I resize the image in the listview to a bigger size ? And I need your help to tell me which changes should I make in the code ?
My code is this:
Code:
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
<asp:ListView ID="ListView1" runat="server" DataKeyNames="Id"
DataSourceID="LinqDataSource1" InsertItemPosition="LastItem"
oniteminserting="ListView1_ItemInserting">
<ItemTemplate>
<li style="">
Description:
<asp:Label ID="DescriptionLabel" runat="server" Text='<%# Bind("Description") %>' />
Tooltip:
<asp:Label ID="TooltipLabel" runat="server" Text='<%# Bind("Tooltip") %>' />
<br />
<asp:Image ID="ImageUrl" runat="server" ImageUrl='<%# Eval("ImageUrl") %>' />
<br />
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" CausesValidation="false"/>
</li>
</ItemTemplate>
<InsertItemTemplate>
<li style="">Description:
<asp:TextBox ID="DescriptionTextBox" runat="server" TextMode="MultiLine" Text='<%# Bind("Description") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="DescriptionTextBox" runat="server" ErrorMessage="Please enter a description"></asp:RequiredFieldValidator>
Tooltip:
<asp:TextBox ID="TooltipTextBox" runat="server" Text='<%# Bind("Tooltip") %>' />
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="TooltipTextBox" runat="server" ErrorMessage="Please enter a tooltip"></asp:RequiredFieldValidator>
<asp:FileUpload ID="FileUpload1" runat="server" />
<br />
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Please select a valid .jpg file"></asp:CustomValidator>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" CausesValidation="false"/>
</li>
</InsertItemTemplate>
<LayoutTemplate>
<ul class="itemContainer">
<li ID="itemPlaceholder" runat="server" />
</ul>
</LayoutTemplate>
</asp:ListView>
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="PlanetWroxDataContext" EnableDelete="True" EnableInsert="True"
TableName="Pictures" Where="PhotoAlbumId == @PhotoAlbumId"
oninserting="LinqDataSource1_Inserting">
<WhereParameters>
<asp:QueryStringParameter DefaultValue="-1" Name="PhotoAlbumId"
QueryStringField="PhotoAlbumId" Type="Int32" />
</WhereParameters>
</asp:LinqDataSource>
</asp:Content>
The .cs is:
Code:
protected void Page_Load(object sender, EventArgs e)
{
int photoAlbumId = Convert.ToInt32(Request.QueryString.Get("PhotoAlbumId"));
using (PlanetWroxDataContext myDatabaseContext = new PlanetWroxDataContext())
{
string photoAlbumOwner = (from p in myDatabaseContext.PhotoAlbums
where p.Id == photoAlbumId
select p.UserName).Single();
if (User.Identity.Name != photoAlbumOwner && !User.IsInRole("Managers"))
{
Response.Redirect("~/");
}
}
}
protected void LinqDataSource1_Inserting(object sender, LinqDataSourceInsertEventArgs e)
{
////////
Picture myPicture = (Picture)e.NewObject;
myPicture.PhotoAlbumId = Convert.ToInt32(Request.QueryString.Get("PhotoAlbumId"));
///////
FileUpload FileUpload1 = (FileUpload)ListView1.InsertItem.FindControl("FileUpload1");
string virtualFolder = "~/GigPics/";
string physicalFolder = Server.MapPath(virtualFolder);
string fileName = Guid.NewGuid().ToString();
string extension = System.IO.Path.GetExtension(FileUpload1.FileName);
FileUpload1.SaveAs(System.IO.Path.Combine(physicalFolder, fileName + extension));
myPicture.ImageUrl = virtualFolder + fileName + extension;
}
protected void ListView1_ItemInserting(object sender, ListViewInsertEventArgs e)
{
FileUpload FileUpload1 = (FileUpload)ListView1.InsertItem.FindControl("FileUpload1");
if (!FileUpload1.HasFile || !FileUpload1.FileName.ToLower().EndsWith(".jpg"))
{
CustomValidator CustomValidator1 = (CustomValidator)ListView1.InsertItem.FindControl("CustomValidator1");
CustomValidator1.IsValid = false;
e.Cancel = true;
}
}
Just need you to guide me to which changes should be made to the code ?