Wrong data in commandargument after applying rowfilter

L

Liza

Hi

I have a problem gettting the right data in my CommandArgument after I
applyed a rowfilter.

My template column looks somewhat like this:

<asp:TemplateColumn HeaderText="ErrorID">
<HeaderStyle Width="30%" CssClass="folderHeader"></HeaderStyle>
<ItemTemplate>
<asp:LinkButton runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.MyId") %>' CommandName="Details" CommandArgument='<%#
DataBinder.Eval(Container, "DataItem.MyId") %>'
CausesValidation="false" ID="lnkbtnDetails">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>

First I bind my datagrid to the datatables default view and everything
works fine. When clicking an item, I get the right ID

Then I apply a rowfilter on the dataview and bind again to the
datagrid:

.....
lDv.RowFilter = "SiteId = " & txtSiteID.Text
dtgItems.DataSource = lDv
dtgItems.DataBind()

Now I get only a few items but when clicking details on, for instance
the second item, in the CommandArgument I get the id from the second
item on the default view and not the second item from the the filtered
view.

Any ideas?

/Liza
 
G

Grant Merwitz

How are you retrieving this value from your code behind?

I gather you are using the ItemCommand event.

Just check that you are not getting the ItemIndex instead of the ItemId

So in your case, rather use:

Ctype(e.Item.FindControls("lnkbtnDetails"), LinkButton).Text (this may
be slightly wrong as i'm a c# coder)

than

e.Item.Itemindex

I also see you are trying to pass this as a COmmandArgument.
Have you checked what the value 'MyId' is placing in your source (through
IE)

HTH
 
L

Liza

wouldn't work with Ctype(e.Item.FindControls("lnk­btnDetails"),
LinkButton).Text since I was only using the same id value as text for
demonstration purposes.

Anyways, I sorted it out.

I am using paging on my grid and therefore needed to set datasource -
even on postback. Unfortunately I also did databinding on postback
which caused my event not to work properly. I changed it, so now I set
the grids datasource on all posts but only do the databinding if it's
not postback. Seems to make both my paging and events work :)

/Liza
 

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

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top