没有时间显示在网格视图页面上

时间:2010-10-20 17:24:38

标签: c# .net sql-server

我正在使用SQL SERVER 2005,C#.NET。

我想仅在我的网格视图页面上显示日期,目前它还显示包含时间。 我正在使用文件上传按钮单击功能恢复表中的日期。 在我的表中我采用了加载日期列数据类型是DateTime。 表格栏中的表格显示为10/19/2010 12:00:00 AM

在我的网格视图页面上,我也会收到日期栏,如10/19/2010 12:00:00 AM

我希望像10/19/2010一样在我的网格上显示。

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

以下是我的代码。请任何人帮我如何在网格视图页面上删除时间。

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";

            }

        }

2 个答案:

答案 0 :(得分:0)

在gridview模板中尝试类似的内容:

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

答案 1 :(得分:0)

如果您正在从数据库表中选择(重新保存存储日期)日期并在Datagridview中显示它使用下面提到的查询,

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

上述查询将以05/09/13格式显示日期。