アプリ版:「スタンプのみでお礼する」機能のリリースについて

現在VisualStudio2005 ASP.NET VBで作成しております。


現在、GridViewを使用しておりまして、バウンドフィールド、ハイパーリンクフィールド、テンプレートフィールド、
をそれぞれ、配置しております。


<asp:ButtonField DataTextField="expression_no" HeaderText="No" SortExpression="expression_no"
Text="ボタン" CommandName="Details" >
<ItemStyle CssClass="GridBorder" />
</asp:ButtonField>

<asp:BoundField DataField="item_name" HeaderText="商品名" SortExpression="item_name" >
<ItemStyle CssClass="GridBorder" />
</asp:BoundField>


<asp:TemplateField HeaderText="年額" SortExpression="moneyPerYear">
<ItemStyle HorizontalAlign="Right" CssClass="GridBorder" />
<ItemTemplate>
<asp:Label ID="moneyPerYearGrid" runat="server" Text='<%# Eval("moneyPerYear", "{0:c0}") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblSummary1" runat="server" ForeColor="Red"></asp:Label>
</FooterTemplate>
<FooterStyle HorizontalAlign="Right" />
</asp:TemplateField>



ハイパーリンクフィールドがクリックされたタイミングで、そのクリックされた行の、データを取得したいと考えております。



Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs)
' コマンド名が“Details”の場合にのみ処理
If e.CommandName = "Details" Then

' 主キー(isbn列)の値を取得
Dim isbn As String = GridView1.DataKeys(e.CommandArgument).Value.ToString
Session("Gridrow") = GridView1.Rows(e.CommandArgument)

Dim datarow As TableRow = Session("GridRow")

Labaffiliation_name.Text = datarow.Cells(0).Text '証明No
Labinsurance_item_name.Text = datarow.Cells(1).Text '商品名
LabPerYearContract.Text = datarow.Cells(2).Text '年金額


End If
End Sub

下記のプログラムを実行すると、データが取得できるのはバウンドフィールドでGridViewにデータバインドしている
Labinsurance_item_name.Text = datarow.Cells(1).Text '商品名
のみで、他のフィールドのデータが取得できません。

どなたかご教授いただけますと幸いです。

A 回答 (1件)

テンプレートフィールドになった時点で、


DataListと同様の扱いになるため、値を取得する場合はFindControlで取得します。

http://msdn.microsoft.com/ja-jp/library/aa479353 …
    • good
    • 0
この回答へのお礼

khazad-lefty 様

Labaffiliation_name.Text = GridView1.Rows(e.CommandArgument).Item(0) '証明No

LabPerYearContract.Text = GridView1.Rows(e.CommandArgument).Item(2) '年金額

で取得することが、できました。
DataListと同様の扱いになるわけなんですね。

テンプレートフィールドの方が、利用しやすいので、積極的に
利用して行こうと思います。
ありがとうございました。

お礼日時:2009/02/26 21:39

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!

このQ&Aを見た人はこんなQ&Aも見ています