PC Review


Reply
Thread Tools Rate Thread

Arrrrrghhhhhhh!

 
 
=?Utf-8?B?Tkg=?=
Guest
Posts: n/a
 
      16th Aug 2005
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!
 
Reply With Quote
 
 
 
 
Grant Merwitz
Guest
Posts: n/a
 
      16th Aug 2005
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" <(E-Mail Removed)> wrote in message
news:75E89A65-CF09-4095-A885-(E-Mail Removed)...
> 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!



 
Reply With Quote
 
=?Utf-8?B?Tkg=?=
Guest
Posts: n/a
 
      16th Aug 2005
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" <(E-Mail Removed)> wrote in message
> news:75E89A65-CF09-4095-A885-(E-Mail Removed)...
> > 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!

>
>
>

 
Reply With Quote
 
Grant Merwitz
Guest
Posts: n/a
 
      16th Aug 2005
woohoo ... about time too!

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

"NH" <(E-Mail Removed)> wrote in message
news:458976AC-3AA8-4311-A310-(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
>> news:75E89A65-CF09-4095-A885-(E-Mail Removed)...
>> > 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!

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:00 AM.