0

In my GridView I have columns called 'F Notes', 'P Notes' and a ImageColumn. After clicking on the ImageButton a popup opens showing the data in the 'F Notes' and 'P Notes'. Now my problem is I do not want the 'F Notes' and 'P Notes' columns to be shown in the background when the pop up opens. I want the data to be visible only in the popup. I know if I change Visible = false then the column will not be shown but when I do that the text in the pop up is not visible.

Below is my code for both HTML and 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;
    }
Sachin
  • 40,216
  • 7
  • 90
  • 102
Valley
  • 71
  • 1
  • 2
  • 10
  • Can you post the `Popup` method? – mshsayem May 14 '13 at 01:38
  • Hi mshsayem, Below is my popup methed protected void Popup(object sender, EventArgs e) { ImageButton btndetails = sender as ImageButton; GridViewRow gvrow = (GridViewRow)btndetails.NamingContainer; lblMrNumber.Text = GridView1.DataKeys[gvrow.RowIndex].Value.ToString(); lblMrNumber.Text = gvrow.Cells[6].Text; txtFNotes.Text = gvrow.Cells[2].Text; txtPNotes.Text = gvrow.Cells[3].Text; this.GridView1_ModalPopupExtender.Show(); } – Valley May 14 '13 at 16:14
  • This may help: http://stackoverflow.com/questions/2818203/get-datakey-values-in-gridview-rowcommand – mshsayem May 15 '13 at 01:39

1 Answers1

0

As "mshsayem" suggested("Get DataKey values in GridView RowCommand"), I believe that you could bypass the visibility problems by defining your "FNotes" and "PNotes" as DataKeys in your GridView. Change DataKeyNames in your GridView too:

DataKeyNames="MrNumber,FNotes,PNotes"

Then in your "Popup" reference the previously defined DataKeys rather than getting the data from the cells themselves.

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(); 
}
Community
  • 1
  • 1
David Rogers
  • 2,601
  • 4
  • 39
  • 84