473,387 Members | 1,283 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Arrrrrghhhhhhh!

NH
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!
Nov 19 '05 #1
3 1272
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!

Nov 19 '05 #2
NH
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" wrote:
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!


Nov 19 '05 #3
woohoo ... about time too!

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

"NH" <NH@discussions.microsoft.com> wrote in message
news:45**********************************@microsof t.com...
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" wrote:
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!


Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.