Please I need help with a datagrid item on edit

Discussion in 'ASP .Net' started by =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=, May 19, 2005.

  1. Hi, I have been on this for hours and just cannot work it out.

    I have a datagrid. I set the edititem index to a row to edit, that works.
    However if i want to put a value into this textbox it wont let me. I just
    cant find the control in the controlcollection for the cell. Is it because it
    hasnt rendered yet? (very annoying as i have set the edititem to the index,
    done my databound etc.) why doesnt it recognise the textbox? so:

    dgThing.EditItemIndex = e.Item.ItemIndex;
    get my source and do DataBind();
    TextBox aBox = (TextBox)e.Item.Cells[2].Controls[0]; //i found this code in
    msdn so i know its right
    thisText.Text="set this text into the textbox";

    Because i have to just work out the cells (there is not cell id) i have just
    counted. I am def on the right one. The one before it has some text in it,
    so i know where i am in the row. but it cant find the textbox control having
    just gone into edit mode. Has anyone got round this somehow? Another thing,
    why do I have to databind again. I only want to change one row yet i have to
    go to my sql database and run a complicated query EVERY time to populate data
    which was already there, just to get my item to go into edit mode! is this
    the only way?
    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=, May 19, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=

    Guest

    Hi

    1) Remember to rebind the datagrid in the EditCommand:

    DataBind()

    2) In OnDataBoundEvent do the:

    TextBox aBox = (TextBox)e.Item.Cells[2].Controls[0];
    thisText.Text="set this text into the textbox";

    Regards,

    Daniel Roth
    MCSD.NET
    , May 19, 2005
    #2
    1. Advertising

  3. Hi Louise,

    In this special situation, you should use

    TextBox aBox = (TextBox)dgThing.Items[e.Item.ItemIndex].Cells[2].Controls[0];

    to get reference of an ‘Edit’ item.

    At this moment, e.Item is a normal datagrid item rather than an edit
    datagrid item.

    HTH

    Elton Wang




    "louise raisbeck" wrote:

    > Hi, I have been on this for hours and just cannot work it out.
    >
    > I have a datagrid. I set the edititem index to a row to edit, that works.
    > However if i want to put a value into this textbox it wont let me. I just
    > cant find the control in the controlcollection for the cell. Is it because it
    > hasnt rendered yet? (very annoying as i have set the edititem to the index,
    > done my databound etc.) why doesnt it recognise the textbox? so:
    >
    > dgThing.EditItemIndex = e.Item.ItemIndex;
    > get my source and do DataBind();
    > TextBox aBox = (TextBox)e.Item.Cells[2].Controls[0]; //i found this code in
    > msdn so i know its right
    > thisText.Text="set this text into the textbox";
    >
    > Because i have to just work out the cells (there is not cell id) i have just
    > counted. I am def on the right one. The one before it has some text in it,
    > so i know where i am in the row. but it cant find the textbox control having
    > just gone into edit mode. Has anyone got round this somehow? Another thing,
    > why do I have to databind again. I only want to change one row yet i have to
    > go to my sql database and run a complicated query EVERY time to populate data
    > which was already there, just to get my item to go into edit mode! is this
    > the only way?
    >
    >
    =?Utf-8?B?RWx0b24gVw==?=, May 19, 2005
    #3
  4. Hi guys thanks for your responses i shall test them out later. Regarding the
    first offering, I think I have already done that??

    "Elton W" wrote:

    > Hi Louise,
    >
    > In this special situation, you should use
    >
    > TextBox aBox = (TextBox)dgThing.Items[e.Item.ItemIndex].Cells[2].Controls[0];
    >
    > to get reference of an ‘Edit’ item.
    >
    > At this moment, e.Item is a normal datagrid item rather than an edit
    > datagrid item.
    >
    > HTH
    >
    > Elton Wang
    >
    >
    >
    >
    > "louise raisbeck" wrote:
    >
    > > Hi, I have been on this for hours and just cannot work it out.
    > >
    > > I have a datagrid. I set the edititem index to a row to edit, that works.
    > > However if i want to put a value into this textbox it wont let me. I just
    > > cant find the control in the controlcollection for the cell. Is it because it
    > > hasnt rendered yet? (very annoying as i have set the edititem to the index,
    > > done my databound etc.) why doesnt it recognise the textbox? so:
    > >
    > > dgThing.EditItemIndex = e.Item.ItemIndex;
    > > get my source and do DataBind();
    > > TextBox aBox = (TextBox)e.Item.Cells[2].Controls[0]; //i found this code in
    > > msdn so i know its right
    > > thisText.Text="set this text into the textbox";
    > >
    > > Because i have to just work out the cells (there is not cell id) i have just
    > > counted. I am def on the right one. The one before it has some text in it,
    > > so i know where i am in the row. but it cant find the textbox control having
    > > just gone into edit mode. Has anyone got round this somehow? Another thing,
    > > why do I have to databind again. I only want to change one row yet i have to
    > > go to my sql database and run a complicated query EVERY time to populate data
    > > which was already there, just to get my item to go into edit mode! is this
    > > the only way?
    > >
    > >
    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=, May 20, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. San Diego Guy
    Replies:
    0
    Views:
    534
    San Diego Guy
    Aug 7, 2003
  2. Schultz
    Replies:
    3
    Views:
    547
    =?Utf-8?B?QmlsbCBCb3Jn?=
    Feb 14, 2005
  3. KK
    Replies:
    2
    Views:
    528
    Big Brian
    Oct 14, 2003
  4. Greg

    Edit Item Template ... Help Please!

    Greg, Apr 26, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    107
    Greg White
    Apr 27, 2004
  5. Ann
    Replies:
    0
    Views:
    143
Loading...

Share This Page