【发布时间】:2016-06-20 15:47:12
【问题描述】:
我的母版页中有位置 DropdownList。我在我的子页面中设置了控件,该控件从母版页获取属性。现在我正在运行一个查询
SELECT * FROM table where city like '"+city.text+"'
这里 city.text 从母版页选定的城市中获取价值。但我的问题是它实际上并没有按照 city.text 显示记录,其中包含值。它显示任何随机记录。
我的代码
母版页
<asp:DropDownList ID="locationSelector" runat="server" AutoPostBack="true">
<asp:ListItem Selected>Pune</asp:ListItem>
<asp:ListItem>Delhi</asp:ListItem>
<asp:ListItem>Chennai</asp:ListItem>
<asp:ListItem>Bangalore</asp:ListItem>
<asp:ListItem>Mumbai</asp:ListItem>
</asp:DropDownList>
子页面VB代码
Dim location As DropDownList = Page.Master.FindControl("locationSelector")
city.Text = location.SelectedItem.ToString
If Not IsPostBack Then
Try
query = "SELECT * FROM hospitals where city like '" + city.Text + "'"
Dim cmd As New MySqlCommand(query, con)
cmd.CommandTimeout = 120
Dim da As New MySqlDataAdapter(cmd)
Dim table As New DataTable
da.Fill(table)
ViewState("Data") = table
hospitals.DataSource = table
hospitals.DataBind()
Catch ex As Exception
Response.Write(ex)
End Try
End If
更新
Protected Sub hospitals_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
Dim location As DropDownList = Page.Master.FindControl("locationSelector")
city.Text = location.SelectedItem.ToString
End Sub
有时它也会抛出 TimeOut 错误。但大多数时候它会得到结果,但不是按照选定的项目。对此还有什么其他解决方案?
【问题讨论】:
-
什么类型的控制是“医院”???
标签: asp.net vb.net master-pages