我正在用 ASP.net C# 开发一个映射应用程序。
我有一个文本框和按钮,它在邮政编码上搜索数据库并将结果返回到我的 aspx 页面上的网格视图中......
public partial class _Default : System.Web.UI.Page
{
// SDE connection string to extract postcode from ADDRESS (sde) table.
private SqlConnection m_sqlConn;
protected void Page_Load(object sender, EventArgs e)
{
}
private void ShowMsg(string strMessage)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
if (txtPostCode.Text.Length > 0)
{
m_sqlConn = new SqlConnection();
m_sqlConn.ConnectionString = "Data Source=Server1;Initial Catalog=sde;User
ID=Tom;Password = Password1";
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.Connection = m_sqlConn;
sqlCmd.CommandType = System.Data.CommandType.Text;
sqlCmd.CommandText = "SELECT * FROM ADDRESS"
+ " WHERE Postcode = '" + txtPostCode.Text + "'";
m_sqlConn.Open();
SqlDataReader reader = sqlCmd.ExecuteReader();
GridView1.DataSource = reader;
GridView1.DataBind();
}
else
{
ShowMsg("Error - No Postal Addresses Returned");
}
}
catch (Exception ex)
{
ShowMsg("Error - " + ex.Message);
}
}
private bool CloseDB()
{
try
{
m_sqlConn.Close();
return (true);
}
catch (Exception ex)
{
return (false);
}
}
}
这工作正常。我现在想在模态弹出窗口中设置数据网格,用户单击搜索按钮并以模态方式返回结果表。我试过用一个假的 ControlID 按钮来设置它,但没有运气......
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Button id="BtnFake" runat="server" Style="display: none"/>
<table id="ModalGrid">
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<asp:Button id="Button2" runat="server" Text="OK" />
</table>
<cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
TargetControlID="BtnFake" PopupControlID="ModalGrid" DropShadow="false"
BackgroundCssClass="ModalBackground"
CancelControlID="BtnOK" BehaviorID="ModalGrid" RepositionMode="RepositionOnWindowScroll">
</cc1:ModalPopupExtender>
有任何想法吗?确定我在做一些明显错误的事情。干杯。