2013-02-21 91 views
3

我需要顯示模塊彈出時gridview行被單擊(沒有任何按鈕),我設法通過單擊gridview行顯示彈出窗口,但不知道將值綁定到文本框在模式彈出顯示.. 所以我需要幫助當單擊gridview行時不顯示模式彈出不使用按鈕

  1. 綁定的GridView行(點擊時)值模式彈出文本框
  2. 模式彈出文本框應該只是編輯當編輯按鈕(放置在模態的底部彈出)被點擊
  3. 編輯工作完成後,它應該保存編輯的數據wh單擊保存按鈕(放置在編輯按鈕旁邊的底部)

作爲asp.net的新手,請嘗試幫助我解決您對我的需求的建議。 因爲下面的代碼是能夠顯示彈出文點擊gridview的行,但建議我怎麼值綁定到文本框:因爲是新來asp.net請儘量

<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 

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代碼幫助我提出你的建議。

回答

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查詢與您的所有新數據。

+0

謝謝Shaharyar !!! 但是我得到DataBindings和customersBindingSource的錯誤(在這種情況下不存在),並且在rowdatabound事件中改變了你的代碼來代替我的代碼,然後告訴我wat是customersBindingSource,它指向哪個?請告訴我我錯了哪裏以及粘貼代碼的位置...... – avrmraja 2013-02-25 11:42:47

相關問題