Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Here's My HTML Code:-

ASP.NET
<div class="col-lg-3 col-md-3" style="float: left">
               <asp:DataList runat="server" ID="dataimg" RepeatColumns="4" RepeatDirection="Horizontal" ItemStyle-CssClass="panel panel-default">
                   <ItemTemplate>
                       <li class="list-group-item list-group" style="width: 200px">
                           <asp:HyperLink ID="HyperLink1" NavigateUrl='<%# String.Concat("Img/",Eval("image")) %>'
                               Target="_blank" runat="server">
                               <img src='Img/<%#Eval("image") %>' alt="15aug" width="160px" height="160px" />
                           </asp:HyperLink>
                           <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>
           </div>



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 = "dd-MM-yyyy";
       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();
       }
   }
Posted
Comments
phil.o 30-Oct-15 7:31am    
You get a SQL error ; what is the datatype of ddate column of date1 table?
Andy Lanng 30-Oct-15 7:41am    
Remember that c# DateTime.MinValue() and default is "01 01 0001" and the min date of mssql is "01 01 1753". Check the date is being parsed correctly
Richard Deeming 30-Oct-15 8:28am    
From the error message, it seems that the ddate column is a string, not a date.

Don't store dates as strings. Use one of the available date types[^].

1 solution

Any possible reason of above error message, you'll find here[^].
 
Share this answer
 

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