开发者

ListView DataKeys Not Being Set/Passed

开发者 https://www.devze.com 2023-03-27 12:12 出处:网络
I am in the process of switching over a control from a GridView to a ListView, but am stuck on accessing the new ListViews DataKeys. My ListView is setup as follows:

I am in the process of switching over a control from a GridView to a ListView, but am stuck on accessing the new ListViews DataKeys. My ListView is setup as follows:

<asp:ListView ID="lvOrderItems" runat="server" 
    DataSourceID="odsShoppingCart"
    DataKeyNames="ProductNumber开发者_开发百科"
    ItemPlaceholderID="lvItemContainer">

Now, on Page_Load I need to do a few calculations, and need the ProductNumber for each ListView row. Here is how I am looping through the ListView:

For Each row As ListViewDataItem In lvOrderItems.Items
    ' Get the row id
    Dim id As String = Convert.ToString(lvOrderItems.DataKeys(row.DisplayIndex).Value)
    Response.Write("rowId=" & id)
Next

And I get the following output for my ListView that has two rows:

rowId=rowId=

So keep in mind, that when I had this as a GridView this was working no problem, and the ListView row labels that are bound directly to the datasouce in my page pull the data fine, so the data, including ProductNumber, is in there...

Any ideas what's going wrong here?


Give this a shot. It's in C#, but should be easy enough to port over to VB.NET

string productName = (string)lvOrderItems.DataKeys[row.DisplayIndex]["ProductNumber"];
0

精彩评论

暂无评论...
验证码 换一张
取 消