0

表示プロパティが none に設定されている更新パネル「PanelSearch」内に gridview を含むテーブルがあります。
ページを最初にロードしたときに、別の更新パネル (メインパネル) 内にあるプレースホルダーにテーブルを追加しました。「PanelSearch」内に検索ボタンがあり、ユーザーが検索をクリックすると、データベースからデータを取得してグリッドビューにバインドします。

グリッドビューには、テンプレート フィールドとしての linkbutton と OnCommand イベントがあります。リンクボタンをクリックしてもイベントは発生しませんが、ページが更新され、「PanelSearch」内のテーブルが消えます。

理由がわかりません 誰か助けてくれませんか?

私のマークアップは次のとおりです。

<asp:UpdatePanel ID="PanelPatientSearch" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <table id="tablePatientSearch" clientidmode="Static" cellpadding="2" cellspacing="2" border="0"
              style=" width:98%;display: table; margin-left: 10px;margin-right: 5px" runat="server" class="table">
              <tr>
              <th style="height:10px;width:100%"></th>
              </tr>
                <tr>
                    <td style="text-align: center">
                        <asp:Label ID="LabelSearchPatient" runat="server" CssClass="sectionHeaderForManagePages"
                            Text="Search Patient"></asp:Label>                          

                    </td>
                </tr>
                <tr>
                    <th style="height:10px;width:100%">
                        &nbsp;
                    </th>
                </tr>
                <tr>
                    <td>
                    <table cellpadding="5" cellspacing="3" width="100%" >
                    <tr> <th colspan="4">
                        &nbsp;
                    </th></tr>
                    <tr>
                    <th class="textCenterAlign" align="center" colspan="4"><asp:Label ID="labelSelectMessage" runat="server" Text="Search for Patient below or"></asp:Label> &nbsp;&nbsp&nbsp;
                    <asp:Button ID="buttonAddNewPatient" runat="server" CssClass="buttonLarge" 
                            Text="Add Patient" onclick="buttonAddNewPatient_Click" CausesValidation="false" />
                    </th>
                    </tr>
                      <tr> <th colspan="4">
                        &nbsp;
                    </th></tr>
                    <tr>
                    <td class="textRightAlign" width="25%">
                        <asp:Label ID="LabelPatientId" runat="server" Text="Patient ID" />
                    </td>
                    <td class="textLeftAlign" width="25%">
                        <asp:TextBox ID="textBoxID" runat="server" ClientIDMode="Static" CssClass="textBox" />
                        <asp:RequiredFieldValidator ID="RFVPatientID" runat="server" ControlToValidate="textBoxID"
                            CssClass="failureNotification" Display="None" ErrorMessage="Patient ID can not be blank"
                            SetFocusOnError="True" Width="0px"></asp:RequiredFieldValidator>
                        &nbsp;
                        <cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender1" runat="server" CssClass="ajaxvalidatorPopup"
                            Enabled="True" TargetControlID="RFVPatientID">
                        </cc1:ValidatorCalloutExtender>
                    </td>
                    <td class="textRightAlign" width="25%">
                        <asp:Label ID="labelFirstName" runat="server" Text="First Name" />
                    </td>
                    <td class="textLeftAlign" width="25%">
                        <asp:TextBox ID="textBoxFirstName" runat="server" CssClass="textBox" />
                    </td>
                    </tr>
                    <tr>
                    <td class="textRightAlign" width="25%">
                        <asp:Label ID="labelLastName" runat="server" Text="Last Name" />
                        <br />
                    </td>
                    <td class="textLeftAlign" width="25%">
                        <asp:TextBox ID="textBoxLastName" runat="server"  CssClass="textBox" />
                        <br />
                    </td>
                    <td class="textRightAlign" width="25%">
                        <asp:Label ID="labelDOB" runat="server" Text="Date of Birth" />
                    </td>
                    <td class="textLeftAlign" width="25%">
                        <asp:TextBox ID="textBoxDOB" runat="server"  CssClass="textBox" />
                        <cc1:CalendarExtender ID="CalendarExtenderAppDate" runat="server" Enabled="True" Format="MM/dd/yyyy" TargetControlID="textBoxDOB">
                        </cc1:CalendarExtender>
                    </td>
                </tr>
                    <tr>
                    <td class="textCenterAlign" colspan="4">
                        <br />
                        <asp:Button ID="buttonSearch" runat="server" CssClass="buttonLarge" 
                            Text="Search" onclick="buttonSearch_Click" ClientIDMode="Static" CausesValidation="false" EnableViewState="false" />
                        <br />
                        <br />
                    </td>
                </tr>
                    <tr>
                    <td colspan="4">
                        <br />
                        <asp:GridView ID="GridViewPatients1" runat="server" AutoGenerateColumns="False" CssClass="GridViewFullWidthCss"
                             EmptyDataText="No Patients are available" AllowPaging="True"  OnRowCommand="GridViewPatients1_RowCommand"
                            AllowSorting="false" EnableViewState="true" ClientIDMode="Static" >

                            <Columns>

                                  <asp:TemplateField HeaderText="Select">
                                     <ItemTemplate>
                                   <asp:LinkButton ID="linkButtonSelect" runat="server" CommandName="Select" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"PatientID") %>' CausesValidation="false" OnCommand="SelectPatient" Text="Select" EnableViewState="true"></asp:LinkButton>

                                     </ItemTemplate>

                                  </asp:TemplateField>


                                <asp:BoundField DataField="PatientID" HeaderText="Patient ID" SortExpression="PatientID">
                                    <ItemStyle Width="20%" />
                                </asp:BoundField>
                                <asp:BoundField DataField="first_name" HeaderText="First Name" SortExpression="FirstName">
                                    <ItemStyle Width="20%" />
                                </asp:BoundField>
                                <asp:BoundField DataField="last_name" HeaderText="Last Name" SortExpression="LastName">
                                    <ItemStyle Width="20%" />
                                </asp:BoundField>
                                <asp:BoundField DataField="birth_date" HeaderText="Date of Birth" SortExpression="DOB">
                                    <ItemStyle Width="20%" />
                                </asp:BoundField>                                  
                            </Columns>
                        </asp:GridView>
                    </td>
                </tr>
                </table>
                </td>
                </tr>  
            </table>
        </ContentTemplate>
        <Triggers>
        <asp:AsyncPostBackTrigger ControlID="buttonSearch" EventName="click" />          
        </Triggers>
    </asp:UpdatePanel>

そして、私のコードビハインドはこのようなものです

protected void SelectPatient(object sender, EventArgs e)
{
        LinkButton lnkSelect = (LinkButton)sender;
        Session["Selected_Patient_Id"] = lnkSelect.CommandArgument;
}
4

2 に答える 2

0

GridView の RowCommand イベントを生成し、それを次のように使用します..

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
   if(e.CommandName == "Select")
   {
       //write what you want to do

   }

}
于 2012-10-30T14:06:50.303 に答える
0

LinkButtonクリックすると、ページの読み込み時にイベントが置き換えられるため、クリックイベントは発生しません。IsPostBackこれを回避するには、 on Page_Load を使用する必要があります。あなたは毎回ページの読み込みDataBindをしていると思います。GridViewしたがって、これを無視して、この方法でコードを使用してください。お悩みのお役に立ちます。

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
          grid.DataSource = dsGrid;
          grid.DataBind();
        }
    }
于 2016-08-30T13:36:38.867 に答える