Cant reference cell text

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default Cant reference cell text

    Hi,

    I'm attempting an update SQl Server using a gatagrid using ADO.

    I am having trouble getting a changed value to work however.

    The datagrid is populated as below:

    sampleNo brush biopsy lavage histology patinetNo
    Edit 87 True True True Squamous 67

    The only editable column is histology.

    I am using the following code to try to update any changes to that
    cell:

    DataRow sRow = dsSample.Tables["Table"].Rows[0];
    sRow["Histology"] = ((TextBox)e.Item.Cells[5].Controls[0];

    But no update occurs. If i change it to:

    DataRow sRow = dsSample.Tables["Table"].Rows[0];
    sRow["Histology"] = "New Text";

    Then it does update. So it seems my cell referencing is wrong. Can
    anyone tell me why? I have tried changing the [5] and [0], but get
    errors.

    Thanks.

    Assimalyst Guest

  2. Similar Questions and Discussions

    1. Moving text into the next cell
      I am working on a large project with a lot of tables. The raw copy/lists come from Word and are in general set up with tabs, which makes it an easy...
    2. Cell Rendering / Change Text
      I have a data grid that is using cellrendering in on of the columns to provide a check box. When I check the box I would like to be able to change...
    3. wrapping text in a datagrid cell
      I have a datagrid that I am having text wrapping problems with. And the wrapping problems only happen with text containing long urls. If I set...
    4. Can't reference a datagrid cell
      Hi All, I'm developing a set of custom controls for a trouble ticket website. I have a class that handles accessing the database for calls such...
    5. Win32-OLE excel cell reference.
      Guys, I'm struggling with the syntax to point to the cells that I want to use in Excel. It seems that the Range command likes data like (A14),...
  3. #2

    Default Re: Cant reference cell text

    Put a breakpoint in the debugger to see how many child controls are under
    the Cell -- there may be more than one if it's a template column.

    -Brock
    DevelopMentor
    [url]http://staff.develop.com/ballen[/url]


    > Hi,
    >
    > I'm attempting an update SQl Server using a gatagrid using ADO.
    >
    > I am having trouble getting a changed value to work however.
    >
    > The datagrid is populated as below:
    >
    > sampleNo brush biopsy lavage histology patinetNo
    > Edit 87 True True True Squamous 67
    >
    > The only editable column is histology.
    >
    > I am using the following code to try to update any changes to that
    > cell:
    >
    > DataRow sRow = dsSample.Tables["Table"].Rows[0];
    > sRow["Histology"] = ((TextBox)e.Item.Cells[5].Controls[0];
    > But no update occurs. If i change it to:
    >
    > DataRow sRow = dsSample.Tables["Table"].Rows[0];
    > sRow["Histology"] = "New Text";
    > Then it does update. So it seems my cell referencing is wrong. Can
    > anyone tell me why? I have tried changing the [5] and [0], but get
    > errors.
    >
    > Thanks.
    >


    Brock Allen Guest

  4. #3

    Default Re: Cant reference cell text

    Thanks for the suggestion Brock.

    I've put a breakpoint in the debugger, i then expanded 'e' then 'Item'
    and found there are listings for 'Cells' and 'cells', i've expanded
    these and the 'owner', then get an option again of expanding 'Cells'
    and 'cells' (amongst others), and it seems i can continue expanding
    'Cells' then 'owner' for quite some time . . .

    Not really sure what i'm looking for from here. Could you point me in
    the right direction please?

    Thanks again.

    Assimalyst Guest

  5. #4

    Default Re: Cant reference cell text

    You can't assign a control, TextBox, to ["Histology"]. You should use a
    string value to update sRow["Histology"] like :
    TextBox txtHistology = ((TextBox)e.Item.Cells[5].Controls[0];
    sRow["Histology"] = txtHistology.Text;


    HTH



    "Assimalyst" <c_oxtoby@hotmail.com> wrote in message
    news:1125928775.560050.307660@g44g2000cwa.googlegr oups.com...
    > Hi,
    >
    > I'm attempting an update SQl Server using a gatagrid using ADO.
    >
    > I am having trouble getting a changed value to work however.
    >
    > The datagrid is populated as below:
    >
    > sampleNo brush biopsy lavage histology patinetNo
    > Edit 87 True True True Squamous 67
    >
    > The only editable column is histology.
    >
    > I am using the following code to try to update any changes to that
    > cell:
    >
    > DataRow sRow = dsSample.Tables["Table"].Rows[0];
    > sRow["Histology"] = ((TextBox)e.Item.Cells[5].Controls[0];
    >
    > But no update occurs. If i change it to:
    >
    > DataRow sRow = dsSample.Tables["Table"].Rows[0];
    > sRow["Histology"] = "New Text";
    >
    > Then it does update. So it seems my cell referencing is wrong. Can
    > anyone tell me why? I have tried changing the [5] and [0], but get
    > errors.
    >
    > Thanks.
    >

    Elton Wang Guest

  6. #5

    Default Re: Cant reference cell text

    Thanks Elton,

    Tried that, but still getting the same behaviour as above. The database
    is not updating.

    I can only presume something is wrong with the
    ((TextBox)e.Item.Cells[5].Controls[0]) statement. But what??

    Thanks again.

    Assimalyst Guest

  7. #6

    Default Re: Cant reference cell text

    One most likely reason is that data in the textbox is overwritten by data
    from database. You might rebind the datagrid's data source before performing
    update function. Normally, we should bind the datagrid's data source when
    IsPostback = false.



    HTH





    "Assimalyst" <c_oxtoby@hotmail.com> wrote in message
    news:1126014179.140686.153930@g14g2000cwa.googlegr oups.com...
    > Thanks Elton,
    >
    > Tried that, but still getting the same behaviour as above. The database
    > is not updating.
    >
    > I can only presume something is wrong with the
    > ((TextBox)e.Item.Cells[5].Controls[0]) statement. But what??
    >
    > Thanks again.
    >

    Elton Wang Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139