c# - How to hide column in GridView after DataBind? -


i ask question because think have different problem : how hide gridview column after databind?

my gridview has data database. don't set "td" in code, html changes gridview table , have "td". problem is, don't want cell or "td" shown on page, want receive data in cell show image in database.

this code retrieve data database:

   public static datatable fetchallimagesinfo(int id)    {      string sb = "select img_content, img_id, csrid images img_id = " + id + ";";      sqlconnection conn = databasefactory.getconnection();      sqldataadapter da = new sqldataadapter(sb, conn);      datatable dt = new datatable();      da.fill(dt);      return dt;     } 

this codebehind bind gridview, here tried set visible true or false, doesn't work. set column index manually because it's has 3 column :

gridview1.datasource = productalllocationcatalog.fetchallimagesinfo(_id); gridview1.databind(); gridview1.columns[0].visible = true; gridview1.columns[1].visible = false; gridview1.columns[2].visible = false; 

and, aspx code :

<asp:gridview id="gridview1" runat="server">   <columns>     <asp:templatefield runat="server">        <itemtemplate runat="server">           <asp:image id="image1" runat="server" imageurl='<%#"handler.ashx?csrid="+eval("csrid") %>' style="max-height:400px; max-width:940px; text-align:center; margin:auto; display:block;" />        </itemtemplate>      </asp:templatefield>   </columns> </asp:gridview>    

i need image database, not other. if select image, gridview can not databind(), , can't value of "csrid".

thank you!

try

protected void gridview_rowdatabound(object sender, gridviewroweventargs e) {     e.row.cells[1].visible = false;     e.row.cells[2].visible = false; } 

i believe issue gridview automatically generating columns, , gridview.columns property stores explicitly declared columns. instead of hiding column, can hide cells comprising columns don't want when each row bound. seems there should better way handle this, outside of using explicitly declared columns, don't know one.


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -