restinpiece @ ウィキ 未編集(いろいろコントロール説明無し自分専用)
※上記の広告は60日以上更新のないWIKIに表示されています。更新することで広告が下部へ移動します。

Partial Class _Default
 
    Inherits System.Web.UI.Page
 
    '一括更新
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
 
        Dim cboxControl
        Dim dlistControl As DropDownList = New DropDownList
 
        Dim Colum1 As String
        Dim Colum2 As String
        Dim Colum3 As String
        Dim Colum4 As String
 
        Dim PostData1 As String = ""
        Dim PostData2 As String = ""
        Dim PostData3 As String = ""
        Dim PostData4 As String = ""
 
        Dim Flag As Boolean = False
        Dim I As Integer
 
        'GridViewの行数分ループする
        For I = 0 To GridView1.Rows.Count - 1
 
            'checkboxのコントロールの取得
            cboxControl = GridView1.Rows(I).FindControl("checkbox1")
            'ドロップダウンリストのコントロールの取得
            dlistControl = GridView1.Rows(I).FindControl("DropDownList1")
 
            'Checkboxのチェック情報を調査
            If cboxControl.checked = True Then
 
                '行ごとのカラムデータを取得
                Colum1 = GridView1.Rows(I).Cells(1).Text + vbTab
                Colum2 = GridView1.Rows(I).Cells(2).Text + vbTab
                Colum3 = GridView1.Rows(I).Cells(3).Text + vbTab
                Colum4 = dlistControl.SelectedItem.Text
 
                'デバッグ表示
                Response.Write(Colum1 & vbTab)
                Response.Write(Colum2 & vbTab)
                Response.Write(Colum3 & vbTab)
                Response.Write(Colum4 & "<br />")
 
                '初回通過時は先頭に,をつけない。
                If Flag = False Then
 
                    '空じゃなければ通過する
                    If Colum1 <> "" Then
 
                        'POST送信用に文字列連結(初回なのでカンマ無し)
                        PostData1 &= Colum1
                        PostData2 &= Colum2
                        PostData3 &= Colum3
                        PostData4 &= Colum4
 
                        Flag = True
 
                    End If
 
                Else
 
                    'POST送信用に文字列連結(2回目以降なのでカンマ有)
                    PostData1 &= "," & Colum1
                    PostData2 &= "," & Colum2
                    PostData3 &= "," & Colum3
                    PostData4 &= "," & Colum4
 
                End If
 
            End If
 
        Next
 
        '更新結果が無ければエラーメッセージを出力しあれば更新処理を行う。
        If Flag = False Then
 
            Response.Write("チェックがついていません。")
 
        Else
 
            Dim St As String
 
            '###########################################################################################
            '更新フォームに値を送信するJavaScript
            '別ウインドウを開き、GridViewの値をPOSTで送信する
            '###########################################################################################
            St = "<form name='driftForm' id='driftForm' action='default2.aspx' method='post' >" & vbCrLf
            St &= "<input type='hidden' name='番号'           value='" & PostData1 & "' />" & vbCrLf
            St &= "<input type='hidden' name='状態選択'       value='" & PostData2 & "' />" & vbCrLf
            St &= "<input type='hidden' name='メールアドレス' value='" & PostData3 & "' />" & vbCrLf
            St &= "<input type='hidden' name='担当者ID'       value='" & PostData4 & "' />" & vbCrLf
            St &= "<input type='hidden' name='処理日'         value='' />" & vbCrLf
            St &= "</form>" & vbCrLf
            St &= "<SCRIPT LANGUAGE='javascript'>" & vbCrLf
            St &= "window.open('default2.aspx','winPopUp','width=640,height480=,toolbar=no,resizable=yes,scrollbars=yes');" & vbCrLf
            St &= "var obj = new Object();" & vbCrLf
            St &= "obj = document.getElementById('driftForm');" & vbCrLf
            St &= "obj.target = 'winPopUp';" & vbCrLf
            St &= "document.driftForm.submit()" & vbCrLf
            St &= "</SCRIPT>" & vbCrLf
 
            Response.Write(St)
 
        End If
 
 
    End Sub
 
    '個別更新
    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
 
        Dim cboxControl
 
        Dim CurrentbuttonID As String
        Dim buttonID As String
 
        Dim dlistControl As DropDownList = New DropDownList
 
        Dim Colum1 As String
        Dim Colum2 As String
        Dim Colum3 As String
        Dim Colum4 As String
 
        '送信イベントからIDを取得
        buttonID = sender.ClientId()
 
        Dim I As Integer
 
        'GridViewの行数分ループする
        For I = 0 To GridView1.Rows.Count - 1
 
            'checkboxのコントロールの取得
            cboxControl = GridView1.Rows(I)
            '現在処理中の行のボタンのIDを取得
            CurrentbuttonID = CType(cboxControl.ClientID, String) + "_Button2"
            'ドロップダウンリストのコントロールの取得
            dlistControl = GridView1.Rows(I).FindControl("DropDownList1")
 
            'イベントハンドラに送られてきたbuttonIDと一致したボタンがある行を対象に処理
            If CurrentbuttonID = buttonID Then
 
                GridView1.Rows(i).Cells.
 
 
                '行ごとのカラムデータを取得
                Colum1 = GridView1.Rows(I).Cells(1).Text + vbTab
                Colum2 = GridView1.Rows(I).Cells(2).Text + vbTab
                Colum3 = GridView1.Rows(I).Cells(3).Text + vbTab
                Colum4 = dlistControl.SelectedItem.Text
 
                'デバッグ表示
                Response.Write(Colum1 & vbTab)
                Response.Write(Colum2 & vbTab)
                Response.Write(Colum3 & vbTab)
                Response.Write(Colum4 & "<br />")
 
                Dim St As String
 
                '###########################################################################################
                '更新フォームに値を送信するJavaScript
                '別ウインドウを開き、GridViewの値をPOSTで送信する
                '###########################################################################################
                St = "<form name='driftForm' id='driftForm' action='default2.aspx' method='post' >" & vbCrLf
                St &= "<input type='hidden' name='番号'           value='" & Colum1 & "' />" & vbCrLf
                St &= "<input type='hidden' name='状態選択'       value='" & Colum2 & "' />" & vbCrLf
                St &= "<input type='hidden' name='メールアドレス' value='" & Colum3 & "' />" & vbCrLf
                St &= "<input type='hidden' name='担当者ID'       value='" & Colum4 & "' />" & vbCrLf
                St &= "<input type='hidden' name='処理日'         value='' />" & vbCrLf
                St &= "</form>" & vbCrLf
                St &= "<SCRIPT LANGUAGE='javascript'>" & vbCrLf
                St &= "window.open('default2.aspx','winPopUp','width=640,height480=,toolbar=no,resizable=yes,scrollbars=yes');" & vbCrLf
                St &= "var obj = new Object();" & vbCrLf
                St &= "obj = document.getElementById('driftForm');" & vbCrLf
                St &= "obj.target = 'winPopUp';" & vbCrLf
                St &= "document.driftForm.submit()" & vbCrLf
                St &= "</SCRIPT>" & vbCrLf
 
                Response.Write(St)
 
            End If
 
        Next
 
    End Sub
 
    '全選択するメソッド
    Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
 
        Dim I As Integer
        Dim hantei
        Dim dlist As DropDownList = New DropDownList
        Dim key As String
 
        key = sender.ClientId()
 
        For I = 0 To GridView1.Rows.Count - 1
 
            hantei = GridView1.Rows(I).FindControl("checkbox1")
            hantei.checked = True
 
        Next
 
    End Sub
 
    '全選択解除するメソッド
    Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
 
        Dim I As Integer
        Dim hantei
        Dim dlist As DropDownList = New DropDownList
        Dim key As String
 
        key = sender.ClientId()
 
        For I = 0 To GridView1.Rows.Count - 1
 
            hantei = GridView1.Rows(I).FindControl("checkbox1")
 
            hantei.checked = False
 
        Next
 
    End Sub
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
    End Sub
 
 
 
 
End Class
 


default.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>無題のページ</title>
</head>
<body>
    <form id="form1" runat="server" >
    <div>
        <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="番号">
            <EditItemTemplate>
                番号:
                <asp:Label ID="番号Label1" runat="server" Text='<%# Eval("番号") %>'></asp:Label><br />
                状態選択:
                <asp:TextBox ID="状態選択TextBox" runat="server" Text='<%# Bind("状態選択") %>'>
                </asp:TextBox><br />
                メールアドレス:
                <asp:TextBox ID="メールアドレスTextBox" runat="server" Text='<%# Bind("メールアドレス") %>'>
                </asp:TextBox><br />
                担当者ID:
                <asp:TextBox ID="担当者IDTextBox" runat="server" Text='<%# Bind("担当者ID") %>'>
                </asp:TextBox><br />
                処理日:
                <asp:TextBox ID="処理日TextBox" runat="server" Text='<%# Bind("処理日") %>'>
                </asp:TextBox><br />
                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                    Text="更新">
                </asp:LinkButton>
                <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                    Text="キャンセル">
                </asp:LinkButton>
            </EditItemTemplate>
            <InsertItemTemplate>
                番号:
                <asp:TextBox ID="番号TextBox" runat="server" Text='<%# Bind("番号") %>'>
                </asp:TextBox><br />
                状態選択:
                <asp:TextBox ID="状態選択TextBox" runat="server" Text='<%# Bind("状態選択") %>'>
                </asp:TextBox><br />
                メールアドレス:
                <asp:TextBox ID="メールアドレスTextBox" runat="server" Text='<%# Bind("メールアドレス") %>'>
                </asp:TextBox><br />
                担当者ID:
                <asp:TextBox ID="担当者IDTextBox" runat="server" Text='<%# Bind("担当者ID") %>'>
                </asp:TextBox><br />
                処理日:
                <asp:TextBox ID="処理日TextBox" runat="server" Text='<%# Bind("処理日") %>'>
                </asp:TextBox><br />
                <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                    Text="挿入">
                </asp:LinkButton>
                <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                    Text="キャンセル">
                </asp:LinkButton>
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
                    Text="新規作成">
                </asp:LinkButton>
            </ItemTemplate>
        </asp:FormView>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="番号"
            DataSourceID="SqlDataSource1" EmptyDataText="表示するデータ レコードがありません。" CellPadding="4" ForeColor="#333333" GridLines="None">
            <Columns>
                <asp:TemplateField HeaderText="選択">
                    <ItemTemplate>
                        &nbsp;<asp:CheckBox ID="CheckBox1" runat="server" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="番号" HeaderText="番号" ReadOnly="True" SortExpression="番号" />
                <asp:BoundField DataField="メールアドレス" HeaderText="メールアドレス" SortExpression="メールアドレス" />
                <asp:BoundField DataField="担当者ID" HeaderText="担当者ID" SortExpression="担当者ID" />
                <asp:BoundField DataField="処理日" HeaderText="処理日" SortExpression="処理日" />
                <asp:CheckBoxField />
                <asp:TemplateField HeaderText="状態選択">
                    <ItemTemplate>
                        &nbsp;
                        <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2" DataTextField="状態名" DataValueField="番号">
                        </asp:DropDownList>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Button" CommandName="wana" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
            <PagerTemplate>
                &nbsp;
            </PagerTemplate>
            <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
            <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>
        &nbsp;
        <asp:Button ID="Button1" runat="server" Text="ALLBUTTON" />&nbsp;
        <asp:Button ID="Button3" runat="server" Text="全選択" EnableTheming="True" />
        <asp:Button ID="Button4" runat="server" Text="全解除" /><br />
        <br />
        <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1">
        </asp:DataList><br />
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString3 %>"
            DeleteCommand='DELETE FROM "テスト" WHERE "番号" = ?' InsertCommand='INSERT INTO "テスト" ("番号", "状態選択", "メールアドレス", "担当者ID", "処理日") VALUES (?, ?, ?, ?, ?)'
            ProviderName="<%$ ConnectionStrings:ConnectionString3.ProviderName %>" SelectCommand='SELECT "番号", "状態選択", "メールアドレス", "担当者ID", "処理日" FROM "テスト"'
            UpdateCommand='UPDATE "テスト" SET "状態選択" = ?, "メールアドレス" = ?, "担当者ID" = ?, "処理日" = ? WHERE "番号" = ?'>
            <DeleteParameters>
                <asp:Parameter Name="番号" Type="String" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="番号" Type="String" />
                <asp:Parameter Name="状態選択" Type="String" />
                <asp:Parameter Name="メールアドレス" Type="String" />
                <asp:Parameter Name="担当者ID" Type="String" />
                <asp:Parameter Name="処理日" Type="DateTime" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="状態選択" Type="String" />
                <asp:Parameter Name="メールアドレス" Type="String" />
                <asp:Parameter Name="担当者ID" Type="String" />
                <asp:Parameter Name="処理日" Type="DateTime" />
                <asp:Parameter Name="番号" Type="String" />
            </UpdateParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"
            DeleteCommand='DELETE FROM "状態マスタ" WHERE "番号" = ?' InsertCommand='INSERT INTO "状態マスタ" ("番号", "状態コード", "状態名") VALUES (?, ?, ?)'
            ProviderName="<%$ ConnectionStrings:ConnectionString2.ProviderName %>" SelectCommand='SELECT "番号", "状態コード", "状態名" FROM "状態マスタ"'
            UpdateCommand='UPDATE "状態マスタ" SET "状態コード" = ?, "状態名" = ? WHERE "番号" = ?'>
            <DeleteParameters>
                <asp:Parameter Name="番号" Type="String" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="番号" Type="String" />
                <asp:Parameter Name="状態コード" Type="String" />
                <asp:Parameter Name="状態名" Type="String" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="状態コード" Type="String" />
                <asp:Parameter Name="状態名" Type="String" />
                <asp:Parameter Name="番号" Type="String" />
            </UpdateParameters>
        </asp:SqlDataSource>
        <br />
        <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="番号"
            DataSourceID="SqlDataSource2" EmptyDataText="表示するデータ レコードがありません。" AllowPaging="True" AllowSorting="True">
            <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                <asp:BoundField DataField="番号" HeaderText="番号" ReadOnly="True" SortExpression="番号" />
                <asp:BoundField DataField="状態コード" HeaderText="状態コード" SortExpression="状態コード" />
                <asp:BoundField DataField="状態名" HeaderText="状態名" SortExpression="状態名" />
            </Columns>
        </asp:GridView>
        <br />
        <br />
        <asp:Localize ID="Localize1" runat="server"></asp:Localize>
        &nbsp;
        &nbsp; &nbsp;
    </div>
    </form>
</body>
</html>