<asp:UpdatePanel ID="up" runat="server">
<ContentTemplate>
<table>
<!-- Main Table start -->
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
<tr>
<td class="auto-style1">
<!-- Left Table Start-->
<table cellspacing="0" cellpadding="0" border="0" style="width: 95%; margin-top:20px">
<tbody>
<tr>
<!--Center Side Start -->
<td align="center" class="style1">
<div class="smallbox" style="margin: 0px">
<table style="margin-left: 20px; width: 278px;
height: 95px;" cellspacing="0" cellpadding="0"
align="center" border="0">
<tbody>
<tr>
<td class="formtext" width="37%"
height="27">
From:
</td>
<td width="63%" align="left"
height="27">
<asp:DropDownList
ID="DropDownList1"
runat="server">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="formtext" width="37%" height="27">
To:
</td>
<td width="63%" align="left" height="27">
<asp:DropDownList ID="DropDownList2" runat="server"></asp:DropDownList>
</td>
</tr>
<tr>
<td class="formtext" width="37%" height="27">
Depart on
</td>
<td width="63%" align="left" height="27">
<asp:TextBox ID="DepartureDate" runat="server"></asp:TextBox>
<asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="DepartureDate"></asp:CalendarExtender>
</td>
</tr>
<tr>
<td class="formtext" height="27%" width="37%">
Rent
</td>
<td align="left" height="37" width="63%">
<asp:Literal ID="litrent1" runat="server" />
</td>
</tr>
</tbody>
</table>
</div>
</td>
</table>
<!-- Main Table End -->
</ContentTemplate>
</asp:UpdatePanel>
这是我的c#代码......
private void bindGrid()
{
string lidhja= "SERVER=localhost\\SqlExpress;Database=Projekti2;" + "Integrated Security=true;";
SqlConnection cnnDB = new SqlConnection(lidhja);
string query = "SELECT a.RouteID,a.Departure,a.Price FROM ListBus a INNER JOIN Route b ON a.RouteID=b.RouteID WHERE a.Departure=@DepartureDate AND b.StartPlace=@StartPlace AND b.DestPlace=@DestPlace";
using (SqlDataAdapter sda = new SqlDataAdapter(query, cnnDB))
{
sda.SelectCommand.Parameters.AddWithValue("@DepartureDate", DepartureDate.Text);
sda.SelectCommand.Parameters.AddWithValue("@StartPlace", DropDownList1.SelectedValue);
sda.SelectCommand.Parameters.AddWithValue("@DestPlace", DropDownList2.SelectedValue);
DataSet ds = new DataSet();
sda.Fill(ds, "ListBus");
GridView1.DataSource = ds.Tables["ListBus"].DefaultView;
GridView1.DataBind();
}
如何看待我想在TextBox和DropDownList1以及DropDownList2中使用文本从我的SQL表中获取一些数据,但这种方式不起作用。 当我改变我的c#代码(见下文)时,它可以工作,但这不是我想要的:
string query = "SELECT a.RouteID,a.Departure,a.Price FROM ListBus a INNER JOIN Route b ON a.RouteID=b.RouteID WHERE a.Departure='2013-12-15' AND b.StartPlace='Austria' AND b.DestPlace='Kosovo';
帮我解决一下!