Programatically Change Datagrid column type?

D

Dan Hartshorn

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top