ben*_*lim 4 vb.net asp.net visual-studio-2010
我有一个vb web形式的datalist.
如何获取数据列表的特定行和单元格中的值?
我可以为detailview做这个,但是如何为datalist做呢?
以下是我的详细信息代码:
Dim selectedCommentAns As String = DetailsView.Rows(0).Cells(1).Text
Run Code Online (Sandbox Code Playgroud)
我为datalist尝试了相同的方法,但它没有选择行和单元格.
这是我的datalist的asp标记:
<asp:DataList ID="DataListPhotoGallery" runat="server" CellPadding="5"
CellSpacing="12" DataKeyField="PhotographerPhotoId"
DataSourceID="SqlDataSourcePhotoGallery" RepeatColumns="3">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" BorderColor="#C7B273"
BorderStyle="Groove" BorderWidth="12px" Height="200px"
ImageUrl='<%# Eval("PhotographerPhotoImgPath", "images/UserUploadedPhoto/{0}") %>'
Width="220px" />
<br />
Photo No:
<asp:Label ID="PhotographerPhotoIdLabel" runat="server"
Text='<%# Eval("PhotographerPhotoId") %>' />
<br />
Photo Description:
<asp:Label ID="PhotographerPhotoDescLabel" runat="server"
Text='<%# Eval("PhotographerPhotoDesc") %>' />
<br />
Photo Name:
<asp:Label ID="PhotographerPhotoImgNameLabel" runat="server"
Text='<%# Eval("PhotographerPhotoImgName") %>' />
<br />
Photographer Name:
<asp:Label ID="PhotographerIdLabel" runat="server"
Text='<%# Eval("PhotographerName") %>' />
<br />
<asp:Button ID="AddCommentBtn" runat="server"
CommandArgument='<%# Eval("PhotographerPhotoId") %>' Font-Bold="True"
Font-Size="Medium" onclick="AddCommentBtn_Click" Text="Add Comment" />
<asp:Button ID="Button2" runat="server"
CommandArgument='<%# Eval("PhotographerPhotoId") %>' Font-Bold="True"
Font-Size="Medium" onclick="Button2_Click" Text="Order Photo" />
<br />
Run Code Online (Sandbox Code Playgroud)
而不是Rows和Cells,DataList有一个名为的属性Items,允许您访问其数据绑定项集合:
Dim itemIndex As Integer = 9
Dim label As Label = DataListPhotoGallery.Items(itemIndex).FindControl("PhotographerPhotoIdLabel")
Dim text As String = label.Text
Run Code Online (Sandbox Code Playgroud)
如果您知道行索引和列索引但不知道项索引,那么您可以像这样计算项索引:
RepeatDirection是Horizontal: itemIndex = rowIndex * RepeatColumns + columnIndexRepeatDirection是Vertical:如果你需要,发表评论,因为它相当复杂.| 归档时间: |
|
| 查看次数: |
3613 次 |
| 最近记录: |