Set Gridview Edit cell to Readonly Bug

Discussion in 'ASP .Net Web Controls' started by vinda, Jun 13, 2006.

  1. vinda

    vinda Guest

    Hello,

    I have this strange bug with a gridview thats got me rather puzzled.

    I have a Gridview assigned to an ObjectDataSource.

    I want to set one of the cells to be Readonly so that you can't change
    this value when you edit the row. But I can't set Readonly directly in
    the BoundField tag as I want this field to be Readonly only with
    objects bound to that row that have a boolean value of 1, in cases of 0
    they can edit this.

    I added the code below thinking this would be the best way to do this,
    but I get a stackOverflow exception as it keeps calling the method
    assigned to the "SelectMethod" of the ObjectDataSource whilst executing
    this code.

    Without setting the Readonly property below, it all works fine. With
    it, it gets stuck in some kind of loop. Can anyone explain why this is
    happening and a possible solution?

    By the way, this also happens if I try to make the BoundField not
    visible.



    protected void grid_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    MyObj obj = (MyObj)e.Row.DataItem;

    if (obj.IsTrue == true)
    {
    DataControlFieldCell cell =
    ((DataControlFieldCell)e.Row.Controls[2]);
    BoundField field1 = (BoundField)(cell.ContainingField);
    field1.ReadOnly = true;
    }
    }
    }
     
    vinda, Jun 13, 2006
    #1
    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. news.rcn.com
    Replies:
    1
    Views:
    9,815
    Chris Smith
    Jul 12, 2004
  2. S_K
    Replies:
    1
    Views:
    3,694
    Yankee Imperialist Dog
    Jun 5, 2008
  3. Patrik

    Set readonly property on cell level in a datagridview

    Patrik, Feb 15, 2007, in forum: ASP .Net Building Controls
    Replies:
    3
    Views:
    535
    Steven Cheng[MSFT]
    Feb 16, 2007
  4. RJ
    Replies:
    1
    Views:
    262
    Eliyahu Goldin
    Feb 17, 2005
  5. Jonathan Hyatt
    Replies:
    1
    Views:
    2,147
    Jonathan Hyatt
    Jun 8, 2004
Loading...

Share This Page