2012-01-28 6 views
4

私はVBウェブフォームのデータリストを持っています。vbのデータリスト。データリスト内の行またはセルの特定の値を取得しようとしています

データリストの特定の行とセルで値を取得するにはどうすればよいですか?

詳細ビューではできますが、データリストではどうすればいいですか?

は下記たDetailsViewのために私のコードです:

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

私はデータリストのために同じ方法を試してみましたが、それは行とセルを選択する必要がいけません。

これは私のデータリストの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 /> 


+0

どこからテキストを取得する必要がありますか? DataListのaspxマークアップとして表示する必要があります。 –

+0

データリストのaspxマークアップで質問を編集しました。「PhotographerPhotoIdLabel」のテキストを取得するにはどうすればよいですか? –

答えて

1

あなたが特定のアイテムにアクセスしたい場合は、

DataListPhotoGallery.Items 

を使用してアイテムにアクセスすることができ、あなたが必要あなたが探しているオブジェクトを見つけることができます。この場合、PhotographerPhotoIdLabelラベルの値を取得する必要があります。あなたが行を知っている場合

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

5

代わりのRowsCellsを助け

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

希望、DataListを使用すると、データバインド項目のコレクションにアクセスすることができますItemsという名前のプロパティを持っています列インデックスはアイテムインデックスではなく、アイテムインデックスを計算することができます。

  • RepeatDirectionの場合はHorizontal次のとおりです。itemIndex = rowIndex * RepeatColumns + columnIndex
  • RepeatDirection場合Verticalです:コメントを投稿それはかなり複雑なので、あなたがこれを必要とする場合。
0

懸念データソースを使用して値を取得できます。必要な値を取得するには、下記のコードを参照してください。

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

希望すると、これが役立ちます。

関連する問題