2017-11-24 19 views
0

私は自分のデータベースにあるレコードのグリッドを表示しようとしていますが、ボタンをクリックすると何も起こりません。 本当にばかな質問を申し訳ありません。総こちらのnoobと私は任意の解決策を見つけるために を試してみましたが、私はどのボタンをクリックした後にグリッドが表示される

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"> 
 
\t \t </asp:GridView> 
 
     test<input id="Hidden1" type="hidden" /></form> 
 
    <p> 
 
     &nbsp;</p> 
 
    </body> 
 
</html>

C#

onclickとは対照的に、
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; 


} 
+0

次の 'IsPostBack、Update Panel、javascript functions 'をグーグルで検索し始めます。 – MethodMan

答えて

0

は、おそらくJavascriptの機能(サーバー側MYPの方法とは反対に)ターゲットしようとしている、OnClickイベントを使用してみてください:あなたの方法であれば、

さらに
<input id="Button1" type="button" value="Search" runat="server" OnClick="Myp" /> 

まだが呼び出されていない場合は、OnClickイベントハンドラが正しく構成され、Mypメソッドを指していることを確認するために、Button1ボタンのイベントプロパティを調べてみる必要があります。

+0

これはまだ動作していませんし、実際に何を意味するのかは実際には分かりませんでした:/ –

+0

ボタンのクリックイベントハンドラの名前を'あなたの特定のボタンのプロパティをチェックし、イベントセクション(稲妻のように見える)を見て、OnClickハンドラがあなたのMypメソッドを指していることを確認し、そのメソッドに設定しますそれがなければ)。 –

関連する問題