Set Gridview Edit cell to Readonly Bug

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

  1. vinda

    vinda Guest


    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

    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 =
    BoundField field1 = (BoundField)(cell.ContainingField);
    field1.ReadOnly = true;
    vinda, Jun 13, 2006
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.