0

私の GridView には、「F Notes」、「P Notes」、および ImageColumn という列があります。ImageButton をクリックすると、ポップアップが開き、「F ノート」と「P ノート」のデータが表示されます。ここで私の問題は、ポップアップが開いたときに「F Notes」列と「P Notes」列を背景に表示したくないということです。データがポップアップでのみ表示されるようにします。Visible = false に変更すると列が表示されないことはわかっていますが、その場合、ポップアップのテキストは表示されません。

以下は、HTML と aspx.cs の両方のコードです。

 <asp:BoundField DataField="FNotes" HeaderText="F Notes" Visible="False" SortExpression="FNotes" />
 <asp:BoundField DataField="PNotes" HeaderText="P Notes" Visible="False" SortExpression="PNotes" />
 <asp:TemplateField HeaderText="Notes">
    <ItemTemplate>
      <asp:ImageButton ID="btnShowPopup" runat="server" Visible='<%#true.Equals(Eval("notesVisible"))%>' ImageUrl="~/Images/Imgs.jpg" Height="30px" Width="30px" OnClick="Popup" />
    </ItemTemplate>
  </asp:TemplateField>

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        GridView1.Columns[2].Visible = true;
        GridView1.Columns[3].Visible = true;
    }
4

1 に答える 1

0

「mshsayem」が示唆したように(「GridView RowCommand で DataKey 値を取得する」)、GridView で「FNotes」と「PNotes」を DataKeys として定義することで、可視性の問題を回避できると思います。GridView の DataKeyNames も変更します。

DataKeyNames="MrNumber,FNotes,PNotes"

次に、「ポップアップ」で、セル自体からデータを取得するのではなく、以前に定義された DataKeys を参照します。

protected void Popup(object sender, EventArgs e) { 
     ImageButton btndetails = sender as ImageButton; 
     GridViewRow gvrow = (GridViewRow)btndetails.NamingContainer; 
     lblMrNumber.Text = (string)GridView1.DataKeys[gvrow.RowIndex]["MrNumber"]; 
     lblMrNumber.Text = gvrow.Cells[6].Text; 
     txtFNotes.Text = (string)GridView1.DataKeys[gvrow.RowIndex]["FNotes"]; 
     txtPNotes.Text = (string)GridView1.DataKeys[gvrow.RowIndex]["PNotes"];  
     this.GridView1_ModalPopupExtender.Show(); 
}
于 2013-11-05T23:42:29.533 に答える