Arrrrrghhhhhhh!

G

Guest

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!
 
G

Grant Merwitz

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 :))
 
G

Guest

Hi Grant,
thanks again!
You know what, I think you have cracked it. What I have now are two template
columns defined, both linking into the same database field. Now based on the
value in another cell I dynamically make visible\invisible the relevant
column. One of the columns has an edititemtemplate control, the other doesnt
so it looks like it will work!

This is a bit of a workaround, but sometimes you need someone to look at a
problem in another way. Thanks Grant, you have saved me probably another 2
days worth of trial and error, mostly error.
Cheers!
N


Grant Merwitz said:
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 said:
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!
 
G

Grant Merwitz

woohoo ... about time too!

I'm going out for drinks now .. i think you should as well :)

NH said:
Hi Grant,
thanks again!
You know what, I think you have cracked it. What I have now are two
template
columns defined, both linking into the same database field. Now based on
the
value in another cell I dynamically make visible\invisible the relevant
column. One of the columns has an edititemtemplate control, the other
doesnt
so it looks like it will work!

This is a bit of a workaround, but sometimes you need someone to look at a
problem in another way. Thanks Grant, you have saved me probably another 2
days worth of trial and error, mostly error.
Cheers!
N


Grant Merwitz said:
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 said:
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!
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top