gridview, strange behaviour

Last post 07-06-2009 3:56 AM by SSA. 4 replies.

Sort Posts:

  • gridview, strange behaviour

    07-02-2009, 1:42 AM
    • Member
      point Member
    • g.minnen
    • Member since 07-02-2009, 5:00 AM
    • Posts 2

    I'm quite new to asp.net so maybe I'm trying something stupid (just tell)

    Have a gridview with about 15 databound columns, 4 of the columns are editable and 1 templatefield.

    In the databound event, I make a new database connection (sqladapter that fills a dataset).

    I do comparisons between the gridview values and the values retrieved from the database. If condition is raised I fill a templatefield in the gridview.

    if (Convert.ToDecimal(datarow[0].ToString()) > Convert.ToDecimal(e.Row.Cells[11].Text))

    {

    e.rows.cell[16].text = ' My message to user';

    }

     

    No problem so far.

    The problem occurs if the gridview field in the comparison is enabled (not read only).

    In that case, the edit button doesn't work. If I click on it, the row doensn't go into edit mode.

    At first I thought there was some strange value in the cell, which couldn't be converted to a decimal. But after setting the column to readonly = true, the problem went away.

    When I start the page in debugmode, an error is raised on the moment I click the edit link.

    FormatException was unhandled by user code. Input string was not in correct format.

    Very strange, this error occurs only on enabled fields.

    I thought to solve the problem, by checking on the rowstate and execute code the code only in the normal state. However databound event is not executed when I click on the edit button, so why is error raised in the databound event when it's not even raised?

    Known issue? What am I doing wrong? Workaround?

    Appreciate any advice.

  • Re: gridview, strange behaviour

    07-02-2009, 9:25 AM
    • Contributor
      2,494 point Contributor
    • SSA
    • Member since 05-07-2009, 3:16 PM
    • Amsterdam, The Nederlands
    • Posts 411

    Can you post your complete code?

  • Re: gridview, strange behaviour

    07-02-2009, 1:19 PM
    Answer
    • Contributor
      7,023 point Contributor
    • superguppie
    • Member since 05-19-2009, 11:42 AM
    • Posts 1,240
    In Edit-mode, the cells don't hold the Text. Instead they hold Controls (such as TextBox) to do the editing. This will have to be taken into account when get-/setting values.
    Superguppie.

    Please remember to click “Mark as Answer” on the post that helps you.
    This can be beneficial to other community members reading the thread.

    When all you've got is a Hammer,
    Every Problem looks like a Nail.
    Michael Swain.
  • Re: gridview, strange behaviour

    07-06-2009, 3:06 AM
    • Member
      point Member
    • g.minnen
    • Member since 07-02-2009, 5:00 AM
    • Posts 2

    SSA:

    Can you post your complete code?

     

     

    What part of my code do you need?

    only event?

     

  • Re: gridview, strange behaviour

    07-06-2009, 3:56 AM
    • Contributor
      2,494 point Contributor
    • SSA
    • Member since 05-07-2009, 3:16 PM
    • Amsterdam, The Nederlands
    • Posts 411

    Your data bound event and databinding code, and before that can you try:

    Convert.ToDecimal(datarow[0].ToString()) insated of this only Convert.ToDecimal(datarow[0]), this is the point where format exception could occur.


Page 1 of 1 (5 items)