加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – vb中的Datalist.试图获取datalist中行或单元格的特定

发布时间:2020-12-16 06:46:53 所属栏目:asp.Net 来源:网络整理
导读:我有一个vb web形式的datalist. 如何获取数据列表的特定行和单元格中的值? 我可以为detailview做这个,但是如何为datalist做呢? 以下是我的详细信息代码: Dim selectedCommentAns As String = DetailsView.Rows(0).Cells(1).Text 我为datalist尝试了相同的
我有一个vb web形式的datalist.

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

我可以为detailview做这个,但是如何为datalist做呢?

以下是我的详细信息代码:

Dim selectedCommentAns As String = DetailsView.Rows(0).Cells(1).Text

我为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:&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 />

解决方法

DataList具有名为Items的属性,而不是Rows和Cells,它允许您访问其数据绑定项的集合:

Dim itemIndex As Integer = 9
Dim label As Label = DataListPhotoGallery.Items(itemIndex).FindControl("PhotographerPhotoIdLabel")
Dim text As String = label.Text

如果您知道行索引和列索引但不知道项索引,则可以像下面这样计算项索引:

>如果RepeatDirection为Horizo??ntal:itemIndex = rowIndex * RepeatColumns columnIndex>如果RepeatDirection为Vertical:如果需要,请发表评论,因为它相当复杂.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读