LinkButton CommandArgument bound property loses value on postback

G

Guest

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.
 
G

Guest

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
 
G

Guest

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top