con.Open();
DataTable d = new DataTable();
adp = new SqlDataAdapter("select tender_register.tender_no,tender_register.date_of_work_order,tender_register.stipulated_date_of_completion,contractor_info.name,contractor_info.phone_no from tender_register,contractor_info where tender_register.tender_no=contractor_info.tender_no AND tender_register.stipulated_date_of_completion between @startDate AND @endDate ", con);
adp.SelectCommand.Parameters.AddWithValue("startDate", TextBox1.Text);
adp.SelectCommand.Parameters.AddWithValue("endDate",TextBox2.Text);
adp.Fill(d);
GridView1.DataSource = d;
GridView1.DataBind();
con.Close();
看起来像这样
我想从日期列中删除该时间,我可以删除它吗?如何删除?
这是html代码
<body>
<form id="form1" runat="server">
<div>
From : <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><img src="../img/calender.png" />  
To : <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><img src="../img/calender.png" />
 <asp:Button ID="submit" Text="submit" runat="server" OnClick="submit_Click" />
<br /><br />
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<br />
</div>
</form>
试试这个:
这是用于项目模板
con.Open();
DataTable d = new DataTable();
adp = new SqlDataAdapter("SELECT TR.tender_no,TR.date_of_work_order,TR.stipulated_date_of_completion,CI.NAME,CI.phone_no FROM tender_register as TR inner join contractor_info as CI on TR.tender_no = CI.tender_no WHERE TR.stipulated_date_of_completion Between @startDate and @endDate ", con);
adp.SelectCommand.Parameters.AddWithValue("startDate", TextBox1.Text);
adp.SelectCommand.Parameters.AddWithValue("endDate",TextBox2.Text);
adp.Fill(d);
mainGrid.DataSource = d;
mainGrid.DataBind();
con.Close();
<asp:GridView ID="mainGrid" runat="server" AutoGenerateColumns="false" CssClass="table table-bordered table-condensed table-hover" OnRowDataBound="mainGrid_RowDataBound" AllowPaging="True" ForeColor="Black">
<Columns>
<asp:TemplateField HeaderText="tender No" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label runat="server" ID="lblaa" Text=' <%# Eval("tender_no") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="From Date" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label runat="server" ID="lbltiming2" Text=' <%# Eval("date_of_work_order","{0:MM-dd-yyyy}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="To Date" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label runat="server" ID="lbltiming1" Text=' <%# Eval("stipulated_date_of_completion","{0:MM-dd-yyyy}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="NAME" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label runat="server" ID="lbltiming" Text=' <%# Eval("NAME") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="phone_no" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label runat="server" ID="lblstatus" Text=' <%# Eval("phone_no") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
这是数据绑定(bind)字段
<asp:GridView ID="mainGrid" runat="server" AutoGenerateColumns="false" CssClass="table table-bordered table-condensed table-hover" OnRowDataBound="mainGrid_RowDataBound" AllowPaging="True" ForeColor="Black">
<Columns>
<asp:BoundField DataField="date_of_work_order" HeaderText="From Date" DataFormatString = "{0:d}" ReadOnly="True" />
<asp:BoundField DataField="stipulated_date_of_completion" HeaderText="To Date" DataFormatString = "{0:d}" ReadOnly="True" />
</Columns>
</asp:GridView>
我是一名优秀的程序员,十分优秀!