Programatically Change Datagrid column type?

Discussion in 'ASP .Net' started by Dan Hartshorn, Apr 13, 2004.

  1. VS.NET 2003, C#, Windows Server 2003. I have a datagrid and I want the
    last column to be either an EditCommandColumn or a template column,
    depending on a value I have. The value changes for each row. So some
    rows will have an EditCommandColumn, others just a text message in the
    last column. Is this possible? I am already using the ItemDataBound
    method to perform some function on each row, but I can't seem to
    change the datagrid's column type programatically.

    I tried some inline C#:

    <%if(myBooValue){%>
    <asp:TemplateColumn...
    <%} else {%>
    <asp:EditCommandColumn...
    <%{%>

    But I received a runtime error: cannot use control block in that
    context. Even if that worked, I'm looking for a way to do it cleanly
    in the code-behind.

    Another idea I had was to define both columns in the aspx datagrid,
    then show-hide them in the code-behind depending on my value for that
    row. But I can't figure out how to programatically ID the columns to
    show or hide them.

    Thanks,
    Dan
    Dan Hartshorn, Apr 13, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kbalz
    Replies:
    2
    Views:
    1,334
    Kbalz
    Oct 4, 2007
  2. EdwardH
    Replies:
    0
    Views:
    504
    EdwardH
    Oct 12, 2008
  3. Audun Simonsen

    Programatically add column

    Audun Simonsen, Feb 2, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    128
    Audun Simonsen
    Feb 3, 2004
  4. Bruno Alexandre

    hide a column programatically

    Bruno Alexandre, Apr 25, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    100
    Manikandan
    May 2, 2006
  5. Angel
    Replies:
    1
    Views:
    122
    Phil H
    Oct 23, 2006
Loading...

Share This Page