这是我的代码 .aspx.cs 页面
public string makequery()
{
string query = string.Empty;
if (ddlPortal2.SelectedValue == "Select" && tbFrom.Text == null && tbTo.Text == null && ddlQuery.SelectedValue == "Select")
{
query = "SELECT * FROM Form3 and ORDER BY CONVERT(VARCHAR(25), [Datetime], 101) between '" + tbFrom.Text + "' and '" + tbTo.Text + "' DESC";
return query;
}
else if(ddlPortal2.SelectedItem.Text!="Select" && tbFrom.Text!=null && tbTo.Text!=null && ddlQuery.SelectedItem.Text=="Select")
{
query = "Select * from Form3 where Portal='" + ddlPortal2.SelectedValue + "' and ORDER BY CONVERT(VARCHAR(25), [Datetime], 101) between '" + tbFrom.Text + "' and '" + tbTo.Text + "' DESC";
return query;
}
else if (ddlPortal2.SelectedItem.Text != "Select" && tbFrom.Text == null && tbTo.Text == null && ddlQuery.SelectedItem.Text != "Select")
{
query = "Select * from Form3 where Portal='" + ddlPortal2.SelectedValue + "' and ORDER BY CONVERT(VARCHAR(25), [Datetime], 101) between '" + tbFrom.Text + "' and '" + tbTo.Text + "' DESC";
return query;
}
return null;
}
public void GridViewBind()
{
string query = makequery();
DataSet ds = new DataSet();
if (ds != null)
{
if (ds.Tables[0].Rows.Count != 0)
{
GridView1.DataSource = ds;
GridView1.DataBind();
}
else
{
GridView1.DataSource = null;
GridView1.DataBind();
}
}
}
protected void btnSearch_Click(object sender, EventArgs e)
{
this.GridViewBind();
}
.aspx 页面代码:
<div id="Portal" runat="server">
<asp:Label ID="lblPortal" runat="server" Text="Select Portal"/>
<asp:DropDownList ID="ddlPortal2" runat="server" AutoPostBack="True">
<asp:ListItem>Select</asp:ListItem>
<asp:ListItem>TRAVELONG</asp:ListItem>
<asp:ListItem>ONETRAVEL</asp:ListItem>
<asp:ListItem>.UK-BSP</asp:ListItem>
<asp:ListItem>.CV-YYZ</asp:ListItem>
<asp:ListItem>.CV-YVR</asp:ListItem>
</asp:DropDownList>
<asp:Label ID="lbFrom" Text="From" runat="server" />
<asp:TextBox ID="tbFrom" runat="server" />
<asp:RequiredFieldValidator ID="rfvFrom" runat="server" ControlToValidate="tbFrom" ErrorMessage="Enter Valid Date">*</asp:RequiredFieldValidator>
<asp:Label ID="lblto" Text="To" runat="server" />
<asp:TextBox ID="tbTo" runat="server" />
<asp:RequiredFieldValidator ID="rfvTo" runat="server" ControlToValidate="tbTo"
ErrorMessage="Enter To date">*</asp:RequiredFieldValidator>
<asp:DropDownList ID="ddlQuery" runat="server" Width="87px">
<asp:ListItem>All</asp:ListItem>
<asp:ListItem Value="Query ">Query</asp:ListItem>
<asp:ListItem>Non Query</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="btnSearch" runat="server" Text="Search"
onclick="btnSearch_Click" ValidationGroup="1"/><br />
<br />
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />
</div>
<div id="Main" runat="server">
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333"
GridLines="None" onrowcommand="GridView1_RowCommand"
AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="Select">
<itemtemplate>
<asp:LinkButton CommandName="cmdBind" runat="server" Text='<%#Eval("ID")%>' ID="ID" ToolTip='<%#Eval("ID")%>'>LinkButton </asp:LinkButton>
</itemtemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date">
<ItemTemplate>
<asp:Label ID="lblDateTime" runat="server" Text='<%# Eval("DateTime","{0:d}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Portal" HeaderText="Portal" SortExpression="Portal" ItemStyle-HorizontalAlign="Center"/>
<asp:BoundField DataField="TID" HeaderText="TID" SortExpression="TID" ItemStyle-HorizontalAlign="Center"/>
<asp:BoundField DataField="PNR" HeaderText="PNR" SortExpression="PNR" ItemStyle-HorizontalAlign="Center"/>
<asp:BoundField DataField="TicketNumber" HeaderText="TicketNumber" SortExpression="TicketNumber" ItemStyle-HorizontalAlign="Center"/>
<asp:TemplateField HeaderText="Unused Tkt Amount" SortExpression="ddlUnusedAmount" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblUnusedAmount" runat="server" Text='<%#Eval("UnusedTicketAmount")+ "-" + Eval("ddlUnusedAmount")%>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Penality" SortExpression="ddlAirlinePenality" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblAirlinePenality" runat="server" Text='<%#Eval("AirlinePenality")+ "-" + Eval("ddlAirlinePenality")%>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Net Refund" SortExpression="ddlNetRefundProcess" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblNetRefund" runat="server" Text='<%#Eval("NetRefundProcess")+ "-" + Eval("ddlNetRefundProcess")%>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Refundable Commission" SortExpression="ddlRefundableCommission" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblRefundableCommission" runat="server" Text='<%#Eval("RefundableCommission")+ "-" + Eval("ddlRefundableCommission")%>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ESACCode" HeaderText="ESACCode" SortExpression="ESACCode" ItemStyle-HorizontalAlign="Center"/>
<asp:BoundField DataField="WaiverCode" HeaderText="WaiverCode" SortExpression="WaiverCode" ItemStyle-HorizontalAlign="Center"/>
<asp:BoundField DataField="RefundType" HeaderText="RefundType" SortExpression="RefundType" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="Comment" HeaderText="Bart Comment" ItemStyle-HorizontalAlign="Center"/>
<asp:BoundField DataField="Query" HeaderText="ARC Verified" ItemStyle-HorizontalAlign="Center" />
</Columns>
现在,我在这里创建了两个函数,一个是进行查询,第二个是在我绑定时dataset
绑定该查询找不到表 0。 gridview
dataset
我想要的是当我选择字段并按下搜索按钮时,我可以根据所选字段在我的网格中查看详细信息,但我无法将它与我的dataset
. 你们能帮我解决这个问题吗?