开发者

How do i pass whole ListView row and use it in external function?

ASP.NET application, VB or C# doesn't matter.

I have Listview which databound to Dataset with about 20 items per row. I have a function which executes on each ItemTemplate appearance and gets about 10 params from Eval("开发者_StackOverflow社区something"). So basically one function builds and image from 10 parameters. Instead of passing 10 Eval("something") to the function is it possible to pass it whole row and how to use this row inside of function because it is not simple DataRow or ListView row which i can access as array of items (datacolumns).

Reason i do that because function looks ugly and each time i need to change it i need to deal with dozens of items.

Thanks


If the ListView is bound to a dataset, you should grab the row from the dataset based on your desired row number.

dim rowNumber as Integer = yourDesiredRowNumber currentDataSet.Tables(tableNumber).Rows(rowNumber)


Use the "ItemDataBound" event. It fires for each row in the list during databinding. You can get your DataRowView for each row and then work with the controls in the ItemTemplate as desired. In this example, I get the DataItem and apply it's data to a Textbox control.

Private Sub ListView1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles ListView1.ItemDataBound
    If e.Item.ItemType <> ListViewItemType.DataItem Then Exit Sub

    Dim dr = DirectCast(e.Item.DataItem, Data.DataRowView)
    Dim Textbox1 = DirectCast(e.Item.FindControl("Textbox1"), Web.UI.WebControls.TextBox)

    Textbox1.Text = dr("MyColumnName")
End Sub
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜