Reputation:
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();
this looks like this
I want to remove that timing from date column can i remove it and how?
this is html code
<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>
Upvotes: 2
Views: 988
Reputation:
Thanks, but got a solution.
Another way is :
write convert(varchar(15), column name, 103) as '[name you want to display as heading]'
in query and just fill datatable and add it as datasource to gridview. It will give same result without using boundfield.
Upvotes: 0
Reputation: 723
Just try this:
this is for itemtemplate
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>
And this is for DataBound Field
<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>
Upvotes: 1