Asp.net vb中的Datalist。尝试获取数据列表中某行或单元格的特定值

Asp.net vb中的Datalist。尝试获取数据列表中某行或单元格的特定值,asp.net,vb.net,visual-studio-2010,Asp.net,Vb.net,Visual Studio 2010,我有一个vb web格式的数据列表 如何获取数据列表中特定行和单元格中的值 我可以为detailsview做,但是如何为datalist做呢 下面是我的detailsview代码: Dim selectedCommentAns As String = DetailsView.Rows(0).Cells(1).Text 我用同样的方法尝试了datalist,但它没有要选择的行和单元格 这是我的数据列表的asp标记: <asp:DataList ID="DataListPhotoGalle

我有一个vb web格式的数据列表

如何获取数据列表中特定行和单元格中的值

我可以为detailsview做,但是如何为datalist做呢

下面是我的detailsview代码:

 Dim selectedCommentAns As String = DetailsView.Rows(0).Cells(1).Text
我用同样的方法尝试了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:&nbsp;
        <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 />


照片编号:
照片说明:
照片名称:
摄影师姓名:



您可以使用

DataListPhotoGallery.Items
如果要访问特定项,则需要查找要查找的对象。在本例中,您希望获得PhotophotoIDLabel标签的值

var PhotographerPhotoIdLabel = DataListPhotoGallery.Items[itemsId].FindControl("PhotographerPhotoIdLabel") as Label;
var yourString = PhotographerPhotoIdLabel.Text;

希望这有助于

而不是
单元格
数据列表
有一个名为
的属性,允许您访问其数据绑定项的集合:

Dim itemIndex As Integer = 9
Dim label As Label = DataListPhotoGallery.Items(itemIndex).FindControl("PhotographerPhotoIdLabel")
Dim text As String = label.Text
如果您知道行和列索引,但不知道项索引,则可以按如下方式计算项索引:

  • 如果
    RepeatDirection
    水平的
    itemIndex=rowIndex*RepeatColumns+columnIndex
  • 如果
    RepeatDirection
    Vertical
    如果需要,请发表评论,因为它相当复杂

您可以使用关注点数据源获取值。请参考以下代码以获取所需的值

Dim dv As DataView
dv = CType(SqlDataSource1.Select(DataSourceSelectArguments.Empty), DataView)
selectedCommentAns = dv.Table.Rows[0][1]

希望这会有所帮助。

您需要从哪里获取文本?您应该显示为数据列表的aspx标记。我已使用数据列表的aspx标记编辑了问题。。我该怎么做才能得到“摄影师照片标签”的文本?