Gridview可编辑文本包含备用行的不同日期格式,但所有格式都相同 [英] Gridview editable text contains different date format for alternate rows but the format is same for all

查看:69
本文介绍了Gridview可编辑文本包含备用行的不同日期格式,但所有格式都相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Gridview可编辑文本包含备用行的不同日期格式,但格式相同...

a几秒钟之前| LINK



我正在尝试在gridview上显示一些数据....它准确地说明了。



在名称为供应日期的列上,它包含的值为



供应日期



5月31-13天



May-30-13



Jun-03-13







但是当我点击编辑按钮时,每行的可编辑文本框中的输出为



供应日期



5月31-13天



5/30/2013 12:00:00 AM //为什么这里是diffrenet



Jun-03-13



我的ASP.net代码为



Gridview editable text contains different date format for alternate rows but the format is same f...
a few seconds ago|LINK

I am trying to display some data on gridview....it dsiplays accurately.

on column with name Supply date and it contains the values as

Supply Date

May-31-13

May-30-13

Jun-03-13



But when i click on edit button the the output in editable text box for every row as

Supply Date

May-31-13

5/30/2013 12:00:00 AM//Why it is diffrenet here

Jun-03-13

My ASP.net code is as

<asp:TemplateField HeaderText="Supply Date">
                           <ItemTemplate>
                                   <asp:Label ID="Label19" runat="server" Text='<%# Eval("supply_date") %>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                   <asp:TextBox ID="TextBox19" runat="server" Text='<%# Eval("supply_date") %>'></asp:TextBox>
                            </EditItemTemplate>
                            </asp:TemplateField>





和vb.net代码为







and vb.net code is as


Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound

       Dim lcl_date As String = Nothing
       If Session("lcl_date") IsNot Nothing Then
           lcl_date = Session("lcl_date")
       End If


       If e.Row.RowType = DataControlRowType.DataRow Then
           Dim podate As DateTime = DataBinder.Eval(e.Row.DataItem, "supply_date")
           If e.Row.RowState = DataControlRowState.Normal Or e.Row.RowState = DataControlRowState.Alternate Then
               Dim lbl5 As Label = CType(e.Row.FindControl("Label19"), Label)
               lbl5.Text = podate.ToString(lcl_date)
           End If
           If e.Row.RowState = DataControlRowState.Edit Then
               Dim txpodate As TextBox = CType(e.Row.FindControl("TextBox19"), TextBox)
               txpodate.Text = podate.ToString(lcl_date)
           End If
       End If


   End Sub

推荐答案

只需将DateColumn绑定为:

Just bind your DateColumn like:
<itemtemplate>
   <asp:Label ID="Label19" runat="server" Text='<%# Convert.ToDateTime(Eval("supply_date")).ToString("dd-MMM-yyyy") %>' ></asp:Label>
</itemtemplate>
<edititemtemplate>
   <asp:TextBox ID="TextBox19" runat="server" Text='<%# Convert.ToDateTime(Eval("supply_date")).ToString("dd-MMM-yyyy") %>'></asp:TextBox>
</edititemtemplate>





- Amit


这篇关于Gridview可编辑文本包含备用行的不同日期格式,但所有格式都相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆