Click here to Skip to main content
15,561,817 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello All,

Below is my code for image to be shown in datalist. But whenever the image is clicked some images path are broken and not visible.

ASP.NET
<asp:DataList runat="server" ID="dataimg" RepeatColumns="4" RepeatDirection="Horizontal"
                             ItemStyle-CssClass="panel" CssClass="table">
                            <ItemTemplate>
                                <li class="list-group-item list-group" style="width: 200px">
                                    <a href='<%# String.Concat("Img/",Eval("image")) %>' class="fancybox"
                                        target="_blank" title='<%#Eval("detail") %>' data-fancybox-group="testgroup">
                                        <img src='Img/<%#Eval("image") %>' alt="image" width="160px" height="160px" />
                                    </a>
                                    <asp:Label ID="Label1" runat="server" CssClass="text text-default" Font-Size="12px" Text='<%#Eval("detail") %>'></asp:Label>
                                    <%--<label id="label">
                                    <a href="<%#"design.aspx?pid="+Eval("ID") %>">View Details</a></label>--%>
                                </li>
                            </ItemTemplate>
                        </asp:DataList>


Below is my C# code:-

C#
 protected void Unnamed1_Click(object sender, EventArgs e)
    {
        // NB: The "as" operator can return null:
        LinkButton lnk = sender as LinkButton;
        if (lnk == null)
        {
            throw new InvalidOperationException("sender is not a LinkButton!");
        }

        DateTime theDate;
        // NB: If your date is in a specific format, use TryParseExact instead.
        string format = "yyyy-MM-dd";
        if (!DateTime.TryParseExact(lnk.Text, format, null, DateTimeStyles.None, out theDate))
        {
            // The text is not a valid date:
            throw new FormatException(string.Format("The value '{0}' is not a valid date.", lnk.Text));
        }

        TextBox1.Text = lnk.Text;

        using (SqlConnection con1 = new SqlConnection(ConfigurationManager.AppSettings["str"]))
        using (SqlCommand cmd = new SqlCommand("SELECT * FROM date1 WHERE ddate = @ddate", con1))
        {
            cmd.Parameters.AddWithValue("@ddate", theDate.Date);

            DataSet ds1 = new DataSet();
            SqlDataAdapter da1 = new SqlDataAdapter(cmd);
            da1.Fill(ds1);

            dataimg.Visible = true;
            dataimg.DataSource = ds1;
            dataimg.DataBind();
        }
    }

Please HELP!!
Posted
Updated 12-Nov-15 16:05pm
Comments
jaket-cp 12-Nov-15 12:07pm    
Can you supply the generated markup for the img tag.
Also where are the images stored on the site?

I assume it has something to do with it img src not pointing to the correct path.

Have a read of this, it may help:
https://css-tricks.com/quick-reminder-about-file-paths/
Deepak Kanswal Sharma 12-Nov-15 20:42pm    
Images are stored in the "Img" folder.
Following is the code for uploading images:-

protected void Button1_Click(object sender, EventArgs e)
{

if (FileUpload1.HasFile)
{
uploadimage(FileUpload1, TextBox2, grouptype);
}

if (FileUpload2.HasFile)
{
uploadimage(FileUpload2, TextBox3, grouptype);
}

if (FileUpload3.HasFile)
{
uploadimage(FileUpload3, TextBox4, grouptype);
}

if (FileUpload4.HasFile)
{
uploadimage(FileUpload4, TextBox5, grouptype);
}

if (FileUpload5.HasFile)
{
uploadimage(FileUpload5, TextBox6, grouptype);
}

if (FileUpload6.HasFile)
{
uploadimage(FileUpload6, TextBox7, grouptype);
}

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Pictures Uploaded Successfully')", true);
}

public void uploadimage(FileUpload f1, TextBox t1, DropDownList d1)
{

SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["str"]);
con.Open();
string stre = System.IO.Path.GetExtension(f1.FileName);
string strng = f1.FileName;
string s = System.DateTime.Now.Ticks.ToString() + "." + stre;
f1.SaveAs(Server.MapPath("Img/") + stre);

//SqlDataAdapter da = new SqlDataAdapter("Select count(*)+1 as d from ddate", con);
//int a = Convert.ToInt32("Select (count(*)+1) as d from ddate");

string query = "insert into date1 values('" + TextBox1.Text + "','" + strng + "','" + t1.Text + "','" + grouptype.SelectedItem.Value + "')";
SqlCommand cmd = new SqlCommand(query, con);
cmd.ExecuteNonQuery();
con.Close();

}
jaket-cp 13-Nov-15 5:59am    
You should reply to the comment so the comment originator (being myself this time) will get a notification.

As I mentioned please supply the generated markup for the img tag.
Use the "Improve question" link/button to update your question.
Also supply the javascript code, the c# code should not be required, if the images are being uploaded as you have stated.

1 solution

Analyze the rendered html. See what are the image urls assigned to those image tags. Make sure the images exist in the required folder.
 
Share this answer
 
Comments
Deepak Kanswal Sharma 12-Nov-15 20:49pm    
Images are stored in the required folder only. All the images are stored in the same folder the problem is some of them don't load whenever a picture is clicked to load in bigger format. Does image size has to deal with it?
I don't think size is the issue. Did you try to load the whole url of the image in browser directly?

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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