Gridview Rowcommand / Rowcreated question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?YmVuamk=?=

    Gridview Rowcommand / Rowcreated question

    Hi,

    I've got a gridview that I bind programmaticall y to a view of a typed
    dataset. One column has a command button, and in the RowCreated event, I test
    to see if it's a DataRow, and if it is, I grab the button and attach a value:

    {
    Response.Write( "<br/>" + e.Row.Cells[1].Controls[0].ToString() +
    "<br/>");
    // Retrieve the LinkButton control from the first column.
    Button addButton = (Button)e.Row.C ells[1].Controls[0];

    // Set the LinkButton's CommandArgument property
    addButton.Comma ndArgument =
    ((DataRowView)e .Row.DataItem)["RowID"].ToString();

    }

    }

    This works fine when the page loads (and I see the response.write) . When I
    click the button for a row, however, I get a null reference exception, not in
    the RowCommand handler but in the RowCreated handler (likely because my data
    source is not persisted, and I'm not refreshing my dataset from the database
    or grabbing it from viewstate on postback - i didn't expect RowCreated to
    fire again).

    As a test, I replaced the line

    addButton.Comma ndArgument = ((DataRowView)e .Row.DataItem)["RowID"].ToString();
    with:
    addButton.Comma ndArgument = Convert.ToStrin g(1);

    I expected to get around the null reference error, which I did, but now, I
    didn't get the response.write! This seems to indicate that with this change,
    it didn't even fire the RowCreated event when it was doing the RowCommand,
    which it seemed to when I was getting the null reference exception.

    So: when a rowcommand is fired, is a rowcreated event fired also? Is this
    based on some condition? (I don't do any rebinding on postback)

    Thanks for any help for this foggy situation.

    -Ben
Working...