开发者

no time display on grid view page

I am using SQL SERVER 2005, C# .NET.

I want to diplay date only on my grid view page, currently it showing including time also. I am restoring date in table with file upload button click function. In my table i took Load date column data type is DateTime. Exaple in table column showing like 10/19/2010 12:00:00 AM

On my grid view page also i am getting date column like 10/19/2010 12:00:00 AM

I want to show on my grid just like 10/19/2010.

string strDate = DateTime.Now.ToShortDateString();
cmd.Parameters.Add("@LoadDate", SqlDbType.DateTime).Value = strDate.ToString();

Below are the my code. Please any one can help me how to remove time on my grid view page.

protected void btnUpload_Click(object sender, EventArgs e)
        {


            // Read the file and convert it to Byte Array
            string strClaimNumber = lblFileUploadCliamNumber.Text.ToUpper();
            string strDate = DateTime.Now.ToShortDateString();

            string strDescription = txtDescription.Text.ToString();
            string filePath = FileUpload1.PostedFile.FileName;
            string filename = Path.GetFileName(filePath);
            string ext = Path.GetExtension(filename);
            string contenttype = String.Empty;

            //Set the contenttype based on File Extension

            switch (ext)
            {
                case ".doc":
                    contenttype = "application/vnd.ms-word";
                    break;
                case ".docx":
                    contenttype = "application/vnd.ms-word";
                    break;
                case ".xls":
                    contenttype = "application/vnd.ms-excel";
                    break;
                case ".xlsx":
                    contenttype = "application/开发者_如何转开发vnd.ms-excel";
                    break;
                case ".jpg":
                    contenttype = "image/jpg";
                    break;
                case ".png":
                    contenttype = "image/png";
                    break;
                case ".gif":
                    contenttype = "image/gif";
                    break;
                case ".pdf":
                    contenttype = "application/pdf";
                    break;

            }

            if (contenttype != String.Empty)
            {


                Stream fs = FileUpload1.PostedFile.InputStream;
                BinaryReader br = new BinaryReader(fs);
                Byte[] bytes = br.ReadBytes((Int32)fs.Length);


                //insert the file into database

                string strQuery = "insert into tblFiles(Name, ContentType, Data, Description, ClaimNumber, LoadDate)" +
                   " values (@Name, @ContentType, @Data, @Description, @ClaimNumber, @LoadDate)";
                SqlCommand cmd = new SqlCommand(strQuery);
                cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = filename;
                cmd.Parameters.Add("@ContentType", SqlDbType.VarChar).Value
                  = contenttype;
                cmd.Parameters.Add("@Data", SqlDbType.Binary).Value = bytes;
                cmd.Parameters.Add("@Description", SqlDbType.VarChar).Value = strDescription.ToString();
                cmd.Parameters.Add("@ClaimNumber", SqlDbType.NVarChar).Value = strClaimNumber.ToUpper();
                cmd.Parameters.Add("@LoadDate", SqlDbType.DateTime).Value = strDate.ToString();
                InsertUpdateData(cmd);
                lblMessage.ForeColor = System.Drawing.Color.Green;
                lblMessage.Text = "File Uploaded Successfully";
                GridView1.DataBind();
            }

            else
            {

                lblMessage.ForeColor = System.Drawing.Color.Red;
                lblMessage.Text = "File format not recognised." +
                  " Upload Word/PDF/Excel formats";

            }

        }


Try something like this inside of your gridview template:

<asp:Label ID="lblDate" Text='<%# String.Format("{0:M/d/yyyy}", Eval("DateColumnName")) %>' runat="server" />


If you are Selecting (retriving the Stored Date) the Date from the database table and displaying it in Datagridview Use the below mentioned Query,

Select Convert(Varchar(15),Datecolumn,1) from Tablename

the above Query will display the date in the 05/09/13 format.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜