Hi NH, me again
I'm not sure why my answer won't work here.
I think this definately needs to be done in the EditCommand method and not
the ItemDataBound.
As those textboxes only appear when the DataGrid's edit command is
activated, so i do not see how you are going to set it invisible in the
ItemDataBound event as i don't think it'll will exists
Moving on to my solution.
Does the item that turns into the textbox you want to hide exist in its own
column like so:
<asp:BoundColumn datafield="TheFieldIWantToHide" />
or
<asp:TemplateColumn>
<ItemTemplate>
<Textbox i want to hide>
</ItemTemplate>
</asp:TemplateColumn>
If so, what you need to do is hide this column on the EditCommand (based on
your criteria), and then show it again in the Cancel or Update command.
So say its the 4th column
private void myDg_EditCommand(Object sender, DataGridCommadnEventArgs e)
{
if(/*some criteria*/)
{
e.Item.Columns[4].Visible = false;
}
myDg.EditItemIndex = e.Item.ItemIndex;
BindGrid();
}
private void myDg_CancelCommane( ... )
{
e.Item.Columns[4].Visible = true;
e.Item.EditItemIndex = -1;
BindGrid();
}
THis should do exactly what you want, as i am using this in my grid to do
the same thing
HTH (and hope it doesn't stray anyone with better answers away from this
thread :))
"NH" <NH@discussions.microsoft.com> wrote in message
news:75**********************************@microsof t.com...
Thanks to those who have tried helping me on this but there is still no
resolution.
I am trying to do something seemingly straightforward, but I just cant do
it. I have a datagrid with some template columns defined. When a user goes
to
edit a row I want one particualr cell in the row only to be editable based
on
the value in another cell. So I want the edititemtemplate control i.e. a
textbox only to become visible based on the value in another cell.
I can capture the value in the other cell easy enough but how can I make
the
edititemcontrol "invisible" and leave the normal itemtemplate control
there
when the datagrid is in edit mode.
I am trying to do this all via the ItemDataBound event of the datagrid.
Maybe there is a way of editing the HTML so the edititemtemplate control
only
comes into play for a row based on another cells value.
Help please!