asp.net datagrid textbox blank in edit mode or "not set to an instance" error

Discussion in 'ASP .Net' started by jason@cyberpine.com, Aug 23, 2005.

  1. Guest

    I've seen a few posts on this issue, but no clear solutions.

    I have a mulitiline textbox inside a datagrid.

    I use TemplateColumn to define as multiline with 3 rows.

    I have other field types like drop downs that have no issue displaying
    last values in edit mode with seemingly more complicated code.

    when I attempt to find my textbox with

    Dim ddlxnotes2 As textbox =
    UserGrid.Items(e.Item.ItemIndex).FindControl("xnotes")
    ddlxnotes2.text = ctype(e.item.FindControl("xnotes"), TextBox).text

    I get error:
    Object reference not set to an instance of an object

    I've tried to simply enter the number

    ddlxnotes2.text = e.Item.Cells(5).text

    but that produces a blank field in edit mode. When I change the feild
    number (from 5) to other fields numbers it does load their set value.

    I tried removing multiline and rows=3 from the asp:textbox tag, but the
    error persist and the field is blank. I am sure it's field number 5 on
    the datagrid as it's the last field, 4 works and 6 produces an out of
    range.


    here's the complete field TAG

    asp:TemplateColumn HeaderText="Notes">
    <itemstyle width=200 />
    <ItemTemplate >
    <asp:Label runat="server" Text='<%# Container.DataItem("xnotes") %>'
    ID="Lblnotes"/>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:textbox textmode=multiline rows=3 width=400 runat="server"
    id="xnotes">
    </asp:textbox>
    </EditItemTemplate>
    </asp:TemplateColumn>


    Thanks in advance for any help or information!
    , Aug 23, 2005
    #1
    1. Advertising

  2. Guest

    Re: asp.net datagrid textbox blank in edit mode or "not set to an instance" error

    GOING NUTS...

    ' this does not work - one of many attempts
    Dim ddlxnotes As TextBox =
    Usergrid.Items(e.Item.ItemIndex).FindControl("xnotes")
    ddlxnotes.text =
    ctype(Usergrid.Items(e.Item.ItemIndex).FindControl("xnotes"),textbox).text


    ' this works but reall need cell 5 which shows up blank
    ' Dim ddlxnotes As TextBox =
    Usergrid.Items(e.Item.ItemIndex).FindControl("xnotes")
    ' ddlxnotes.text = e.Item.cells(4).text

    ' this works
    ' Dim ddlxnotes As TextBox =
    Usergrid.Items(e.Item.ItemIndex).FindControl("xnotes")
    ' ddlxnotes.text = "x"


    <asp:TemplateColumn HeaderText="Notes">
    <itemstyle width=400 />
    <ItemTemplate >
    <asp:Label runat="server" Text='<%# Container.DataItem("xnotes") %>'
    ID="Lblnotes"/>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:textbox textmode=multiline rows=3 width=400 runat="server"
    id="xnotes">
    </asp:textbox>
    </EditItemTemplate>
    </asp:TemplateColumn>


    Everything else on the datagrid , including so Edititemtemplates for
    dropdowns displays the last value in edit mode....


    What on earth am I doing wrong?
    , Aug 24, 2005
    #2
    1. Advertising

  3. Re: asp.net datagrid textbox blank in edit mode or "not set to an instance" error

    Dim xNote as TextBox = cType(e.Item.FindControl("xNotes"), TextBox)
    should work. Try this. e.Item is a reference to the row that is being called
    to be editied.

    Regards,

    Trevor Benedict R
    MCSD


    <> wrote in message
    news:...
    > GOING NUTS...
    >
    > ' this does not work - one of many attempts
    > Dim ddlxnotes As TextBox =
    > Usergrid.Items(e.Item.ItemIndex).FindControl("xnotes")
    > ddlxnotes.text =
    > ctype(Usergrid.Items(e.Item.ItemIndex).FindControl("xnotes"),textbox).text
    >
    >
    > ' this works but reall need cell 5 which shows up blank
    > ' Dim ddlxnotes As TextBox =
    > Usergrid.Items(e.Item.ItemIndex).FindControl("xnotes")
    > ' ddlxnotes.text = e.Item.cells(4).text
    >
    > ' this works
    > ' Dim ddlxnotes As TextBox =
    > Usergrid.Items(e.Item.ItemIndex).FindControl("xnotes")
    > ' ddlxnotes.text = "x"
    >
    >
    > <asp:TemplateColumn HeaderText="Notes">
    > <itemstyle width=400 />
    > <ItemTemplate >
    > <asp:Label runat="server" Text='<%# Container.DataItem("xnotes") %>'
    > ID="Lblnotes"/>
    > </ItemTemplate>
    > <EditItemTemplate>
    > <asp:textbox textmode=multiline rows=3 width=400 runat="server"
    > id="xnotes">
    > </asp:textbox>
    > </EditItemTemplate>
    > </asp:TemplateColumn>
    >
    >
    > Everything else on the datagrid , including so Edititemtemplates for
    > dropdowns displays the last value in edit mode....
    >
    >
    > What on earth am I doing wrong?
    >
    Trevor Benedict R, Oct 22, 2005
    #3
    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. =?Utf-8?B?TmV3VG9Eb3ROZXQ=?=

    TextBox and DropDownList in Datagrid Edit mode

    =?Utf-8?B?TmV3VG9Eb3ROZXQ=?=, Jan 30, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    791
    =?Utf-8?B?TmV3VG9Eb3ROZXQ=?=
    Feb 9, 2004
  2. Yunus Emre ALPÖZEN [MCAD.NET]
    Replies:
    1
    Views:
    706
  3. Sharon McCarty
    Replies:
    0
    Views:
    248
    Sharon McCarty
    Nov 24, 2004
  4. Frank Kurka
    Replies:
    8
    Views:
    305
  5. Brian Rupert

    Datagrid Edit mode TextBox Size

    Brian Rupert, Sep 1, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    129
    jon smith
    Sep 15, 2004
Loading...

Share This Page