updatepanel 内にグリッドビューがあります。gridview のフィールドの 1 つは、次のlinkbutton
ようなASP.net です。
<ItemTemplate>
<asp:LinkButton ID="hlSortOrder" runat="server" CssClass="hlDialog" OnClick="LoadLog"
Text='<%# DataBinder.Eval(Container, "DataItem.SortOrder") %>'></asp:LinkButton>
</ItemTemplate>
誰かがリンクボタンをクリックすると、OnClick
私が作成した というメソッドが呼び出されLoadLog
ます。LoadLog は次のようになります。
protected void LoadLog(object sender, EventArgs e)
{
GridViewRow gr = (GridViewRow)((DataControlFieldCell)((LinkButton)sender).Parent).Parent;
Label l = (Label)gr.FindControl("lblID");
DataSet ds;
ds = BL.GetRunoffAnswerLog(Convert.ToInt64(l.Text));
if (ds != null)
{
if (ds.Tables[0].Rows.Count == 0)
{
gvLog.Visible = false;
gvLog.DataSource = null;
lblRowsCount.Text = "No log for this record!";
}
else
{
lblRowsCount.Text = ds.Tables[0].Rows.Count.ToString() + " row(s) found for this record.";
gvLog.DataSource = ds.Tables[0];
gvLog.DataBind();
gvLog.Visible = true;
}
}
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "openDialog", "$('#dialog').dialog({draggable: true, modal: true, height: 500, width: 750, title: 'Log', open: function (type, data) {$(this).parent().appendTo('form');}});", true);
}
基本的に、グリッド ビューの行のハンドルを取得し、データベースからデータを取得して gvLog ソースに割り当てます。その後、最後の行に注意してください。
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "openDialog", "$('#dialog').dialog({draggable: true, modal: true, height: 500, width: 750, title: 'Log', open: function (type, data) {$(this).parent().appendTo('form');}});", true);
ダイアログボックスを開くことができるように、これを行う必要があります。これを初めて取得したときにのみ、グリッドビューの行をクリックすると:
実際にはタイトルしか表示されていないことに注意してください...変です。しかし、同じ行をもう一度クリックすると、ダイアログ全体が表示されます。
最初のクリックでのみ発生します。別の行をクリックし続けると、正常に機能します。次の jquery コードを追加する必要があることを付け加えておきます。
<script type="text/javascript">
$(document).ready(function () {
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function () {
$("#dialog").hide();
// re-bind your jQuery events here
});
....more code...
この議論に基づいて: jQuery $(document).ready and UpdatePanels?
そのコードを持っていない場合、ポストバックが発生した分、このダイアログが含まれている div 全体が常にページに表示され、それは望ましくありません...
以下のメンバーの一人が述べたように。サーバー側のコードでこのイベントを発生させたとしても、実際に開いているダイアログを開くクライアント側のイベントが最初に発生しているリンクボタンを初めてクリックすると、何が起こっていると思います...上記のように、 「LoadLog」イベントをクリックすると、この jquery opendialog が登録されます。しかし、これでも最初にダイアログが開き、2回目にクリックするとデータが表示されるようです。