Web サイトに検索機能を設定したいと考えています。ユーザーはテキスト ボックスに情報を入力し、検索ボタンをクリックします。検索ボタンをクリックすると、テキストボックス内のテキストを使用してデータベースが検索され、結果が表に表示されます。テキスト ボックス内のテキストがデータベースからの 1 つの結果と完全に一致する場合は、結果のリストを表示するのではなく、一致した結果に関する詳細情報がページに表示されます。
結果を正確に一致させやすくするために、各結果の横にボタンを追加して、その結果を「選択」し、テキスト ボックスにその結果のテキストを入力して、ページに詳細を入力します。これが私が持っているものです。
検索ボタンをクリックすると、結果が正確に一致するかどうかを確認した後、結果とボタンを含むテーブルを作成します。
for(int x=0; x < res_list.Length; x++)
{
TableRow newRow = new TableRow();
TableCell textCell = new TableCell();
TableCell buttonCell = new TableCell();
buttonCell.ID = "bc" + x;
Button cellButton = new Button();
cellButton.ID = "btn" + x;
textCell.Text = res_list[x];
textCell.Attributes.Add("Width","60%");
cellButton.Text = x.ToString();
// cellButton.OnClientClick = "NameClick"; This property refers to client-side scripts, which I am not using.
cellButton.Click += new EventHandler(NameClick);
buttonCell.Controls.Add(cellButton);
newRow.Cells.Add(firstCell);
newRow.Cells.Add(buttonCell);
myTable.Rows.Add(newRow);
}
上記の OnClientClick メソッドと Click メソッドの両方を試しましたが、どちらも同じ結果が得られました。
My NameClick 関数は次のとおりです。
void NameClick(object sender, EventArgs e)
{
Button sendButton = (Button)sender;
int index = Int32.Parse(sendButton.Text);
SearchTextBox.Text = myTable.Rows[index].Cells[0].Text;
return;
}
NameClick 関数の先頭にブレークポイントを設定しましたが、これらのボタンの 1 つをクリックしても到達しません。この関数がボタンから呼び出されないのはなぜですか?
編集: 可能であれば、JavaScript を使用せずにこれを実現したいと考えています。