【发布时间】:2017-11-24 13:52:33
【问题描述】:
好吧,我正在尝试显示我在数据库中的记录网格,但是每当我单击按钮时,什么都没有发生 抱歉问了这么一个愚蠢的问题,但我在这里完全是菜鸟,我试过了 找到任何解决方案,但我找不到任何解决方案
HTML:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
enter something</div>
<p>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</p>
<p>
<input id="Button1" type="button" value="Search" runat="server" onclick="Myp" /></p>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
test<input id="Hidden1" type="hidden" /></form>
<p>
</p>
</body>
</html>
C#
protected void Myp(object sender, System.EventArgs e)
{
//Get the button that raised the event
//Button btn = (Button)sender;
string connStr = ConfigurationManager.ConnectionStrings["MyDbConn"].ToString();
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
SqlCommand cmd = new SqlCommand("SearchByName", conn);
cmd.CommandType = CommandType.StoredProcedure;
string name = TextBox2.Text;
cmd.Parameters.Add(new SqlParameter("@name", name));
GridView1.EmptyDataText = "No Records Found";
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
// SqlDataAdapter adapter = cmd.ExecuteReader();
//adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
GridView1.Visible = true;
}
【问题讨论】:
-
开始搜索以下
IsPostBack, Update Panel, and javascript functions
标签: c# html sql visual-studio