3

グリッドビューの行がクリックされたときに(ボタンなしで)モーダルポップアップを表示する必要があります。グリッドビューの行をクリックしてポップアップを表示できましたが、モーダルポップアップに表示されるテキストボックスに値をバインドする方法がわかりません。

  1. gridview行(クリックした場合)の値をモーダルポップアップテキストボックスにバインドします
  2. モーダルポップアップテキストボックスは、編集ボタン(モーダルポップアップの下部に配置)がクリックされた場合にのみ編集可能である必要があります
  3. 編集作業が完了したら、保存ボタン(編集ボタンの横の下部に配置)をクリックすると、編集したデータが保存されます。

asp.netは初めてなので、私の要件に関する提案を手伝ってください。以下のコードにより、グリッドビューの行をクリックするとポップアップが表示されますが、値をテキストボックスにバインドする方法を教えてください。

protected void grid_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            GridViewRow row = e.Row;

            if (row.DataItem == null)
            {
                return;
            }

            try
            {
                switch (e.Row.RowType)
                {
                    case DataControlRowType.Header:
                        break;

                    case DataControlRowType.DataRow:
                        e.Row.Attributes.Add("onmouseover", "this.style.cursor='hand'");
                        e.Row.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(grid, "Select$" + e.Row.RowIndex.ToString()));
                        e.Row.Attributes.Add("onclick", String.Format("javascript:$find('{0}').show();", ModalPopupExtender2.ClientID));


                        TextBox1.Text = grid.SelectedRow.Cells[0].Text;
                        TextBox2.Text = grid.SelectedRow.Cells[1].Text;
                        TextBox3.Text = grid.SelectedRow.Cells[2].Text;
                        TextBox4.Text = grid.SelectedRow.Cells[3].Text;
                        TextBox5.Text = grid.SelectedRow.Cells[4].Text;

                        ModalPopupExtender2.Show();
                        break;
                }
            }

            catch
            {
                return;
            }
        }

HTMLコード:

<asp:Panel ID="editpanel" runat="server">
            <table width="850px" border="1" class="color">
            <tr>
            <td align="center">
            <asp:Label ID="Label1" runat="server" Text="Firstname" Width="150px"></asp:Label>
            <asp:Label ID="Label2" runat="server" Text="Surname" Width="150px"></asp:Label>
            <asp:Label ID="Label3" runat="server" Text="Visits" Width="150px"></asp:Label>
            <asp:Label ID="Label4" runat="server" Text="$ Speed" Width="150px"></asp:Label>
            <asp:Label ID="Label5" runat="server" Text="Points" Width="150px"></asp:Label>
            <asp:ImageButton id="ImageButton1" runat="server" src="close.png" onclick="close_Click" style="float:right; height: 16px;" ToolTip="To close window"/>
            </td>
            </tr>
            <tr>
            <td>
            <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
            <asp:TextBox ID="TextBox2" runat="server"  ></asp:TextBox>
            <asp:TextBox ID="TextBox3" runat="server" ></asp:TextBox>
            <asp:TextBox ID="TextBox4" runat="server" ></asp:TextBox>
            <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
            </td>
            </tr>
            <tr>
                <td>
                        <asp:ImageButton ID="cancell" runat="server" onclick="cancell_Click"  
                        src="cancel.jpg" style="float:right; width: 16px;" 
                        ToolTip="To cancel member" />                    
                    <asp:ImageButton ID="tickk" runat="server" onclick="tickk_Click" src="tick.jpg" 
                        style="float:right; height: 16px;" ToolTip="To save member" />            
                     <asp:ImageButton ID="Edit" runat="server" onclick="edit_Click"  
                        src="edit.jpg" style="float:right; height: 16px; width: 16px;" 
                        ToolTip="To edit member" />
                </td>
                </tr>
            </table>   
            </asp:Panel>
    <asp:ModalPopupExtender ID="ModalPopupExtender2" runat="server" TargetControlID="modal2" PopupControlID="editpanel" BackgroundCssClass="modalBackground"></asp:ModalPopupExtender>


       <asp:ImageButton ID="modal2" runat="server" src="addmember.jpg" OnClick="modal2_click" Text="modal2" style="display:none;"/> // have created a dummy image button

asp.netは初めてなので、提案を手伝ってください。

4

1 に答える 1

0

BindingSourceこれを使用して、(単なる例)を使用してデータをテキストボックスにバインドします。

textBoxid.DataBindings.Add(new Binding("Text", customersBindingSource, "ID"));
textBoxname.DataBindings.Add(new Binding("Text", customersBindingSource, "NAME"));
textBoxcity.DataBindings.Add(new Binding("Text", customersBindingSource, "City"));

テキストボックスを編集不可にするには、次を使用します。

private void EditButton_Click(object sender, EventArgs e)
        {
            if (textBoxid.ReadOnly == true)
            {
                textBoxid.ReadOnly = false;
                //how many text boxes you have, do the same here
            }
            else
            {
                textBoxid.ReadOnly = true;
                //how many text boxes you have, do the same here
            }
        }

編集内容を保存するには、UPDATEすべての新しいデータでクエリを実行するだけです。

于 2013-02-21T13:22:15.623 に答える