views:

24

answers:

2

I am using 2 linkbuttons inside seperate dataitem server controls on my asp.net web page

<asp:LinkButton ID="Item1" runat="server"  CommandName="first"  
      OnCommand="Item1_Onclick" CommandArgument="<%# Container.DataItem %`>"  
      Text="<%# Container.DataItem %`>" >    
</asp:LinkButton`>

and

<asp:LinkButton ID="Item2" runat="server"  CommandName="second"  
      OnCommand="Item2_Onclick" CommandArgument="<%# Container.DataItem %`>"  
      Text="<%# Container.DataItem %`>" >    
</asp:LinkButton`>

When I extract the command name inside c# as

e.CommandArgument.ToString().Trim();    

it does give me the correct the name however the command arugument

e.CommandArgument.ToString().Trim();  

for item2 is not what I expect. It is NOT that of item1, but the one that I set initially as datasource for the datalist control of item2. It does not give me the latest dataitem string value that I am expecting out of item2 linkbutton. What can be the problem? Where am I wrong?

Also, the event for item2 is fired ONLY for the first time and not after that? Is there some silly mistake that I am doing?

A: 

In the command argument you are not providing the property name in the data item

"<%# Container.DataItem.ProeprtyName %`>"

Say your datasource is a User object and you need the userid as the command argument it should be <%# Container.DataItem.UserID%>`

Suhumar
A: 

I got the problem. I had not included the if(!IsPostBack) as the first statement in my void Page_Load method !! That was stupid of me. Thanks anyways for all your time and ideas.

VP