LinkButton CommandArgument bound property loses value on postback

Discussion in 'ASP .Net' started by =?Utf-8?B?QmVuamFtaW4gSm9sZGVyc21h?=, Aug 21, 2004.

  1. Hello all,

    My basic problem is that my LinkButton does not support a data bound
    CommandArgument property under certain cases. The intent is to filter my
    datagrid based on a specific row's value, so one query might return players
    from multiple schools; clicking on a player row's school linkbutton will
    filter the previous query to that school.

    The linkbuttons bind properly (including the commandArgument) when the
    templatecolumn is early in the columns collection. Later in the collection,
    given a certain state, I remove two of the columns from the collection,
    because data is not available to populate them. Unfortunately, if I put the
    tempate column that contains the Linkbutton with the bound CommandArgument
    property after the deleted columns, the command argument always shows up as
    an empty string, "".

    I'm stumped. I am getting ready to just databind the DataTable and query
    the table based on the row index - but is resource intensive, and clunky,
    especially on higher data pages.

    Any suggestions?

    Ben Joldersma
    Sr. Software Developer,
    Citadel Media Inc.
     
    =?Utf-8?B?QmVuamFtaW4gSm9sZGVyc21h?=, Aug 21, 2004
    #1
    1. Advertising

  2. I said databind the DataTable in the last paragraph - I mean to say store the
    DataTable in the ViewState.

    Also, if I debug the application, immediately after the databind occurs,
    examination of the DataGrid1.Items[0].Cells[ IndexOfLinkButtonCell
    ].Controls[ IndexToLinkButtonControl ].CommandArgument reveals the correct
    value. So something is being lost between this point and when I receive
    control in the DataGrid_ItemCommand event.

    --ben
     
    =?Utf-8?B?QmVuamFtaW4gSm9sZGVyc21h?=, Aug 21, 2004
    #2
    1. Advertising

  3. Success.

    I figured out a solution. The reason I wanted to remove the invalid columns
    was because my application would raise an exception when it was trying to
    databind the BoundColumns (the error was that the column reference didn't
    exist in the DataTable.) I had tried previously to just set the invalid
    columns visible propety to false, but the error would still raise. So now,
    for the bound columns, I set the DataField property to null, then set the
    visible property to false, instead of removing the columns entirely. Now the
    CommandArgument property on the later columns is preserved correctly!

    --ben
     
    =?Utf-8?B?QmVuamFtaW4gSm9sZGVyc21h?=, Aug 21, 2004
    #3
    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. Patrick Olurotimi Ige

    commandargument in linkbutton Question

    Patrick Olurotimi Ige, Jun 20, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    2,267
    Patrick Olurotimi Ige
    Jun 20, 2005
  2. Replies:
    3
    Views:
    13,449
    swati254
    Dec 23, 2008
  3. MattB
    Replies:
    4
    Views:
    1,453
    MattB
    Jan 25, 2008
  4. lax4u
    Replies:
    0
    Views:
    802
    lax4u
    Mar 13, 2008
  5. Bigloopy

    ImageButton loses CommandArgument

    Bigloopy, Apr 4, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    638
    George Ter-Saakov
    Apr 4, 2008
Loading...

Share This Page