By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,846 Members | 1,629 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,846 IT Pros & Developers. It's quick & easy.

Programatically Change Datagrid column type?

P: n/a
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
Nov 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.