c# - GridView Column Visibility -


in gridview have columns called 'f notes', 'p notes' , imagecolumn. after clicking on imagebutton popup opens showing data in 'f notes' , 'p notes'. problem not want 'f notes' , 'p notes' columns shown in background when pop opens. want data visible in popup. know if change visible = false column not shown when text in pop not visible.

below code both 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;     } 

as "mshsayem" suggested("get datakey values in gridview rowcommand"), believe bypass visibility problems defining "fnotes" , "pnotes" datakeys in gridview. change datakeynames in gridview too:

datakeynames="mrnumber,fnotes,pnotes" 

then in "popup" reference defined datakeys rather getting data cells themselves.

protected void popup(object sender, eventargs e) {       imagebutton btndetails = sender 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();  } 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -