我正在使用aspx和aspx.cs文件。
我需要有按钮onclick事件,它将数据发送到cs文件以对数据库执行某些操作。
到目前为止,我唯一的问题是如何发送所选的数据。
我的aspx页面是
<form id="form1" runat="server">
<asp:Button ID="city" runat="server" Text="London" value="London" onclick="Page_Load" />
<asp:Button ID="city" runat="server" Text="Paris" value="Paris" onclick="Page_Load" />
<asp:Button ID="city" runat="server" Text="Madrid" value="Madrid" onclick="Page_Load" />
</form>
和aspx.cs页面是
protected void Page_Load(object sender, EventArgs e)
{
String city= Request.QueryString["city"];
SqlConnection sqlCon = new SqlConnection("xx");
sqlCon.Open();
SqlCommand sqlCmd = new SqlCommand("Select * from Table where City = city", sqlCon);
....
}
所以问题是我不知道如何发送所选的值。我该怎么做?感谢
答案 0 :(得分:0)
您在混淆Click事件和Page Load事件时,请转到:
<form id="form1" runat="server">
<asp:Button ID="city" runat="server" Text="London" value="London" OnClick="Button_Click" />
<asp:Button ID="city" runat="server" Text="Paris" value="Paris" OnClick="Button_Click" />
<asp:Button ID="city" runat="server" Text="Madrid" value="Madrid" OnClick="Button_Click" />
</form>
protected void Button_Click(object sender, EventArgs e)
{
String city= Request.QueryString["city"];
SqlConnection sqlCon = new SqlConnection("xx");
sqlCon.Open();
SqlCommand sqlCmd = new SqlCommand("Select * from Table where City = city", sqlCon)
}