
実現したいこと
- [ ]web formでlistviewコントロールを一度ページでbindさせたあとに、取得に時間のかかる情報を取得出来次第アイテム(行)別にloadingから表示に切り替えていく
前提
asp.netのwebformでwebアプリケーションを作成しています。
基本情報|付加情報
会員A|Loading..
会員B|Loading..
会員C|Loading..
このようなテーブル構造でまずはページを表示させます。
ページ自体の読み込みが完了した後、Aの情報が取得でき次第、Loadingから付加情報Aを表示させます。このときBCの付加情報がまだ取得できていなければLoadingのままにします。
上のような仕様で作成したいのですが、うまくいかない状態にあります。
updatepanelとupdateprogressを使用するのかなとおもいますが、行全体の付加情報を更新するならともかく別々に取得出来次第表示というのがどのように実装すればよいか思いつきません。
よろしくお願いいたします。
やったこと
以下コードでやってみました。
ページの初期表示は問題なくできました。取得のボタンを押した際にloadingからhello worldの文字も表示されますが、実際にやりたいこととしてはこれを全行に対して並列的に行いたいです(ページ読込後に全行のボタンをおすようにjsでクリックさせるつもりでした)。
ただupdatepanelでは部分的に変わっているのは表示上のみで、実際にはpostbackが毎回走っているはずなので、ボタンイベントが完了しないまま連続的に1,2,3行目とおしても最後におしたボタンの行のみの更新となってしまいます。
WebForm1.aspx
html
1<html xmlns="http://www.w3.org/1999/xhtml"> 2<head runat="server"> 3<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 4 <title></title> 5 6</head> 7<body> 8 <form id="form1" runat="server"> 9 <div> 10 <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> 11 <asp:ListView ID="ListView1" runat="server"> 12 <LayoutTemplate> 13 <table> 14 <tr> 15 <th>ID</th> 16 <th></th> 17 </tr> 18 <tr id="itemPlaceHolder" runat="server"></tr> 19 </table> 20 </LayoutTemplate> 21 <ItemTemplate> 22 <tr> 23 <td><%# Eval("ID") %></td> 24 <td> 25 <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1"> 26 <ProgressTemplate> 27 Loading.. 28 </ProgressTemplate> 29 </asp:UpdateProgress> 30 <asp:UpdatePanel ID="UpdatePanel1" runat="server"> 31 <ContentTemplate> 32 <asp:Label ID="Label1" runat="server" Text=""></asp:Label> 33 <asp:Button ID="Button1" runat="server" Text="取得" OnClick="Button1_Click" /> 34 </ContentTemplate> 35 </asp:UpdatePanel> 36 </td> 37 </tr> 38 </ItemTemplate> 39 </asp:ListView> 40 </div> 41 </form> 42</body> 43</html>
WebForm1.aspx.vb
vb
1Public Class WebForm1 2 Inherits System.Web.UI.Page 3 4 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 5 If Not IsPostBack Then 6 ListView1.DataSource = GetDataSource() 7 ListView1.DataBind() 8 End If 9 End Sub 10 11 Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) 12 'ここで付加情報をDBから取得する想定 13 System.Threading.Thread.Sleep(5000) 14 Dim str As String = "Hello World" 15 Dim i As Integer = CType(sender, Button).CommandArgument 16 CType(ListView1.Items(i).FindControl("Label1"), Label).Text = str 17 End Sub 18 19 Private Sub ListView1_DataBound(sender As Object, e As EventArgs) Handles ListView1.DataBound 20 For i As Integer = 0 To ListView1.Items.Count - 1 21 CType(ListView1.Items(i).FindControl("Button1"), Button).CommandArgument = i 22 Next 23 End Sub 24 25 Function GetDataSource() As DataTable 26 '基本情報の取得 27 End Function 28End Class
補足情報(FW/ツールのバージョンなど)
.net framework 4.8




