简体   繁体   English

单击gridview行而不使用按钮时不显示模态弹出窗口

[英]modal popup not displayed when clicked gridview row without using button

I need to display a modal popup when gridview row is clicked(without any buttons), i managed to display popup by clicking the gridview row but dont know to bind values to textbox displayed in modal popup.. So i need help to 我需要在点击gridview行时显示模态弹出窗口(没有任何按钮),我设法通过单击gridview行显示弹出窗口但不知道将值绑定到模态弹出窗口中显示的文本框..所以我需要帮助

  1. Bind gridview row(when clicked) values to modal popup textboxes 将gridview行(单击时)值绑定到模态弹出文本框
  2. Modal popup textboxes should only be editable when a edit button(placed at bottom of modal popup) is clicked 只有在单击编辑按钮(位于模态弹出窗口的底部)时,才能编辑模态弹出文本框
  3. After editing work is done, it should save the edited data when clicked save button(placed at bottom next to edit button) 编辑完成后,应该在点击保存按钮时保存编辑后的数据(放在编辑按钮旁边的底部)

As am new to asp.net please try to help me with your suggestions for my requirements. 作为asp.net的新手,请尽量帮助我提出我的要求。 Because of below code am able to show popup wen clicked gridview row but suggest me how to bind values to textbox: 由于下面的代码我能够显示弹出单击gridview行,但建议我如何将值绑定到文本框:

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 CODE: 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

Since am new to asp.net please try to help me with your suggestions. 由于我是asp.net的新手,请尽量帮助我提出建议。

Use this to bind your data with text box by using BindingSource (Just an example): 使用它来使用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"));

To make uneditable your text boxes, use this: 要使您的文本框不可编辑,请使用:

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
            }
        }

To save your edits, just run an UPDATE query with all your new data. 要保存编辑内容,只需运行包含所有新数据的UPDATE查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM