Lill Lansey
Lill Lansey

Reputation: 4915

How do I get the values of the controls in the first row of a listview in c# aspnet?

I can get the the first row in a ListView item in .NET 3.5 by:

ListViewDataItem theFirstItem = ListView1.Items[0];

But then how do I get the get the value of the item's CommandArgument ( an int) < %# Eval("PKey") %> in the aspx.

Or get the contents of

<asp:Label ID="lblStatus" runat="server" Text= '<%# Eval("Status") % /> 

Upvotes: 0

Views: 3976

Answers (2)

Lill Lansey
Lill Lansey

Reputation: 4915

Thanks mgroves!

Got the value of the command argument by:

ListViewDataItem item = ListView1.Items[0]; 
Button btnRead = (Button)item.FindControl("btnRead"); 
int pkey = int.Parse( btnRead.CommandArgument) ; 

I should have asked sooner!

Upvotes: 0

Matthew Groves
Matthew Groves

Reputation: 26096

Does FindControl work for ListView items?


ListViewDataItem theFirstItem = ListView1.Items[0];
Label lblStatus = (Label)theFirstItem.FindControl("lblStatus")
Response.Write(lblStatus.Text);      // outputs the text of that label

Upvotes: 2

Related Questions