View Single Post
  #1 (permalink)  
Old April 3rd, 2012, 03:22 AM
KnightErrant KnightErrant is offline
Registered User
Points: 17, Level: 1
Points: 17, Level: 1 Points: 17, Level: 1 Points: 17, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2011
Location: INDIA
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Angry Display image in gridview according to selected date of user

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"></asp:TextBox>

<asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="TextBox1">
</asp:CalendarExtender>

</div>


using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
public partial class View : System.Web.UI.Page
{
string strcon = ConfigurationManager.ConnectionStrings["con"].ToString();

protected void Page_Load(object sender, EventArgs e)
{
string str = TextBox1.Text;

CultureInfo[] cultures = { CultureInfo.CreateSpecificCulture("en-US") };
foreach (CultureInfo culture in cultures)
{
DateTime date;
date = DateTime.Parse(str, culture);
}
//string str = TextBox1.Text;
// DateTime date = DateTime.ParseExact(str, "yyyy/MM/DD", null);
//System.DateTime str_date = DateTime.Parse(TextBox1.Text, System.Globalization.CultureInfo.CreateSpecificCul ture("en-AU").DateTimeFormat);
//var userdateformat = DateTime.ParseExact(" ' " + TextBox1.Text.ToString() + " ' ", "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture);

Load_GridData();

}
void Load_GridData()
{
SqlConnection conn = new SqlConnection(strcon);
conn.Open(); // open the connection
SqlDataAdapter Sqa = new SqlDataAdapter("select Image, ImageName from Img where ([Date] = @date) ", conn);
DataSet ds = new DataSet();
Sqa.Fill(ds); // fill the dataset
GridView1.DataSource = ds; // give data to GridView
GridView1.DataBind();
conn.Close();
}
}


ERROR:- STRING IS NOT RECOGNIZED AS VALID DATETIME.
date is save in yyyy-mm-dd formate in database.
Reply With Quote