現在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 '商品名
のみで、他のフィールドのデータが取得できません。
どなたかご教授いただけますと幸いです。
No.1ベストアンサー
- 回答日時:
テンプレートフィールドになった時点で、
DataListと同様の扱いになるため、値を取得する場合はFindControlで取得します。
http://msdn.microsoft.com/ja-jp/library/aa479353 …
khazad-lefty 様
Labaffiliation_name.Text = GridView1.Rows(e.CommandArgument).Item(0) '証明No
LabPerYearContract.Text = GridView1.Rows(e.CommandArgument).Item(2) '年金額
で取得することが、できました。
DataListと同様の扱いになるわけなんですね。
テンプレートフィールドの方が、利用しやすいので、積極的に
利用して行こうと思います。
ありがとうございました。
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
このQ&Aを見た人はこんなQ&Aも見ています
-
あるあるbotに投稿したけど採用されなかったあるある募集
あるあるbotに投稿したけど採用されなかったあるあるをこちらに投稿してください
-
フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
あなたが普段思っている「これまだ誰も言ってなかったけど共感されるだろうな」というあるあるを教えてください
-
映画のエンドロール観る派?観ない派?
映画が終わった後、すぐに席を立って帰る方もちらほら見かけます。皆さんはエンドロールの最後まで観ていきますか?
-
海外旅行から帰ってきたら、まず何を食べる?
帰国して1番食べたくなるもの、食べたくなるだろうなと思うもの、皆さんはありますか?
-
天使と悪魔選手権
悪魔がこんなささやきをしていたら、天使のあなたはなんと言って止めますか?
-
GridViewの行選択イベントを発生させるには?
JavaScript
-
ASP.NetのGridViewで任意の行クリックで選択を行う方法
Microsoft ASP
-
GridviewとDataGridviewの違い
Microsoft ASP
-
-
4
GridViewからチェックボックスでデータを選択し、次のページへ送信する動作について
Microsoft ASP
-
5
GridViewにバインドせずにデータを表示する方法
Microsoft ASP
-
6
ASP.NET TextBox 入力制限
Microsoft ASP
-
7
asp.netにてgridviewの列を動的にボタンやチェックボックスを追加して実装したいのですが具
Microsoft ASP
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・人生のプチ美学を教えてください!!
- ・10秒目をつむったら…
- ・あなたの習慣について教えてください!!
- ・牛、豚、鶏、どれか一つ食べられなくなるとしたら?
- ・【大喜利】【投稿~9/18】 おとぎ話『桃太郎』の知られざるエピソード
- ・街中で見かけて「グッときた人」の思い出
- ・「一気に最後まで読んだ」本、教えて下さい!
- ・幼稚園時代「何組」でしたか?
- ・激凹みから立ち直る方法
- ・1つだけ過去を変えられるとしたら?
- ・【あるあるbot連動企画】あるあるbotに投稿したけど採用されなかったあるある募集
- ・【あるあるbot連動企画】フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
- ・映画のエンドロール観る派?観ない派?
- ・海外旅行から帰ってきたら、まず何を食べる?
- ・誕生日にもらった意外なもの
- ・天使と悪魔選手権
- ・ちょっと先の未来クイズ第2問
- ・【大喜利】【投稿~9/7】 ロボットの住む世界で流行ってる罰ゲームとは?
- ・推しミネラルウォーターはありますか?
- ・都道府県穴埋めゲーム
- ・この人頭いいなと思ったエピソード
- ・準・究極の選択
このQ&Aを見た人がよく見るQ&A
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
phpのファイルがブラウザで開か...
-
エクセルに張り付けた写真のフ...
-
MS onedriveの中にあるaccessプ...
-
onedrive にexcelファイルをア...
-
キヤノン アソビカメラ iNSPiC ...
-
VBAでPDFを作成する際、同じ名...
-
vba 空のデータをSplitする時の...
-
バッチファイル IF文の書き方に...
-
VBAでPDF作成をしたあと、指定...
-
aspxをhtmlに変換する方法について
-
asp.netにてgridviewの列を動的...
-
SPIの非言語の割合と比が難しく...
-
ffftpでファイル取得が0バイト...
-
【VB.NET】for each文からのINS...
-
Windows10にデュアルブートでXP...
-
VB.NETでMSComm が追加できず?
-
スイッチが二台あり、別々のア...
-
Excel 条件集計
-
SPO2測定
-
高校1年生情報の問題について。
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
ページの更新内容が反映されない。
-
隠しフィールドをVBScriptでの...
-
Response.Redirectで引数2つの...
-
GridViewからテンプレートフィ...
-
SqlDataSource SelectCommand ...
-
Tableを動的に増やしたい。
-
「a.v.v」「iiMK」の...
-
ASPでpingを飛ばす事は、可能で...
-
GridView表示の高速化
-
【ASP.NET】 ログインコントロ...
-
ASPからASPを呼び出す方法
-
Panelを重ねる方法
-
asp.net でのドロップダウンリ...
-
時々処理が呼ばれない
-
<ASP.NET>DataGridでOnSelected...
-
ASPへのデータの受け渡しについて
-
ビデオテープに貼るラベルシー...
-
北原化粧品をお使いの方へ
-
UpdatePanel と GridViewについ...
-
javascriptでRadioButton操作
おすすめ情報