【发布时间】:2015-10-27 06:27:41
【问题描述】:
我有下面的 GridView:
我想从日期列中删除0:00:00(如果存在)。我更改了dataformatstring,但也删除了9:09:15。
我在.cs 文件上使用auto-generate fields 和DataBind。
我试过Replace,但还是不行:
e.Row.Cells[0].Text = e.Row.Cells[0].Text.Replace("0:00:00"," ");
我该怎么做?
网格视图:
<asp:GridView ID="GridView4" runat="server" BackColor="White"
BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3"
GridLines="Vertical" Width="98%"
Height="100%" onrowdatabound="GridView4_RowDataBound" RowStyle-HorizontalAlign="Center" >
<AlternatingRowStyle BackColor="#DCDCDC" />
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#0000A9" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#000065" />
</asp:GridView>
代码:
protected void Page_Load(object sender, EventArgs e)
{
try
{
OleDbConnection Connection6;
using (Connection6 = new OleDbConnection("Provider=MSDAORA.1;Data Source=XXXXXX:1521/orcl;Persist Security Info=True;Password=XXXXXXX;User ID=XXXXXX;"))
{
string sqlQuery = "select * from db.user";
using (OleDbDataAdapter cmd = new OleDbDataAdapter(sqlQuery, Connection6))
{
Connection6.Open();
DataTable dt = new DataTable();
cmd.Fill(dt);
GridView4.DataSource = dt;
GridView4.DataBind();
Connection6.Close();
}
}
}
catch (Exception)
{
}
}
【问题讨论】:
-
that 列的类型是什么?例如,您可以将其
DataFormatString属性设置为{0:dd.MM.yyyy}。 -
您在哪里提供此代码
e.Row.Cells[0].Text = e.Row.Cells[0].Text.Replace("0:00:00"," ");如果不是,我希望您在数据绑定中使用相同的代码 -
GridView 中的列部分在哪里?