2016-07-04 9 views
1

テキストボックスの値が表示されません。私のコードで何が間違っていますか?モーダルが表示されますが、テーブルの値は取得されません。私はそれの行コマンドを作って、そこにコードを入れました。ショーはありません。誰かが私を助けてくれますか?値は私のモーダルには表示されません

ありがとうございました!

これは、ここに私は.csコード

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 
    { 
     int i = Convert.ToInt32(e.CommandArgument); 



     GridViewRow gvrow = GridView1.Rows[i]; 
     txtID.Text = gvrow.Cells[0].Text; 
     txtType.Text = gvrow.Cells[1].Text; 
     txtModel.Text = gvrow.Cells[2].Text; 
     txtQuan.Text = HttpUtility.HtmlDecode(gvrow.Cells[3].Text); 
     txtUnit.Text = HttpUtility.HtmlDecode(gvrow.Cells[4].Text); 
     txtDate.Text = HttpUtility.HtmlDecode(gvrow.Cells[5].Text); 
     txtDesc.Text = HttpUtility.HtmlDecode(gvrow.Cells[6].Text); 


     //txtID.Text = GridView1.Rows[i].Cells[0].Text.ToString(); 


      lblResult.Visible = false; 

      System.Text.StringBuilder sb = new System.Text.StringBuilder(); 
      sb.Append(@"<script type='text/javascript'>"); 
      sb.Append("$('#editModal').modal('show');"); 
      sb.Append(@"</script>"); 
      ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "EditModalScript", sb.ToString(), false); 


    } 

である私のモーダルdivのコードは私のGridViewいただきました間違って私のコードで1

<asp:UpdatePanel ID="panel1" runat="server"> 
    <ContentTemplate> 
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" DataKeyNames="TransactionID" OnRowDataBound="GridView1_OnRowDataBound" OnRowCommand="GridView1_RowCommand" CellPadding="4" AllowPaging="true" PageIndex="2" OnPageIndexChanging="GridView1_PageIndexChanging" HeaderStyle-BackColor ="CornflowerBlue" BorderWidth="1" BorderColor="Gray" Width="100%" CssClass=" table table-hover" > 
    <Columns> 
     <asp:TemplateField> 
      <ItemTemplate> 
       <asp:CheckBox ID="chkSelect" runat="server" /> 
      </ItemTemplate> 
     </asp:TemplateField> 
     <asp:TemplateField> 
      <ItemTemplate> 
       <img style="cursor:pointer" src ="../Images/Icons/plus2.png" /> 
       <asp:Panel ID ="pnlDetails" runat="server" Style="display: none"> 
        <asp:GridView ID="gvDet" runat="server" AutoGenerateColumns="false" CssClass="ChildGrid"> 
         <Columns> 
          <%--<asp:BoundField ItemStyle-Width="20px" DataField="ID" HeaderText="ID" />--%> 
          <asp:BoundField ItemStyle-Width="200px" DataField="ItemType" HeaderText="Type" /> 
          <asp:BoundField ItemStyle-Width="250px" DataField="ItemModel" HeaderText="Model" /> 
          <asp:BoundField ItemStyle-Width="140px" DataField="ItemQuantity" HeaderText="Requested Quantity" /> 
          <asp:BoundField ItemStyle-Width="80px" DataField="ItemUnit" HeaderText="Unit" /> 
          <asp:BoundField ItemStyle-Width="100px" DataField="ItemDate" HeaderText="Date Needed" /> 
          <asp:BoundField ItemStyle-Width="200px" DataField="ItemDesc" HeaderText="Description" /> 
          <%--<asp:BoundField ItemStyle-Width="80px" DataField="ItemStatus" HeaderText="Status" />--%> 
         </Columns> 
        </asp:GridView> 
       </asp:Panel> 
      </ItemTemplate> 
     </asp:TemplateField> 
     <asp:TemplateField HeaderText="Transaction Number" HeaderStyle-ForeColor="White"> 
      <ItemTemplate> 
       <asp:Label ID ="lblmosID" runat="server" Text='<%#Bind ("TransactionID") %>'></asp:Label> 
      </ItemTemplate> 
      <ItemStyle Width="30px" Font-Size="15px" Font-Names="Calibri" /> 
     </asp:TemplateField> 
     <asp:TemplateField HeaderText="Date" HeaderStyle-ForeColor="White"> 
      <ItemTemplate> 
       <asp:Label ID ="lblDate" runat="server" Text='<%#Bind ("DateFiled") %>'></asp:Label> 
      </ItemTemplate> 
      <ItemStyle Width="130px" Font-Names="Calibri" /> 
     </asp:TemplateField> 
     <asp:TemplateField HeaderText="Name" HeaderStyle-ForeColor="White"> 
      <ItemTemplate> 
       <asp:Label ID ="lblName" runat="server" Text='<%#Bind ("ReqName") %>'></asp:Label> 
      </ItemTemplate> 
      <ItemStyle Font-Names="Calibri" /> 
     </asp:TemplateField> 
     <asp:TemplateField HeaderText="Company" HeaderStyle-ForeColor="White"> 
      <ItemTemplate> 
       <asp:Label ID ="lblComp" runat="server" Text='<%#Bind ("ReqCompany") %>'></asp:Label> 
      </ItemTemplate> 
      <ItemStyle Font-Names="Calibri" /> 
     </asp:TemplateField> 
     <asp:TemplateField HeaderText="Branch" HeaderStyle-ForeColor="White"> 
      <ItemTemplate> 
       <asp:Label ID ="lblBranch" runat="server" Text='<%#Bind ("ReqBranch") %>'></asp:Label> 
      </ItemTemplate> 
      <ItemStyle Font-Names ="Calibri" /> 
     </asp:TemplateField> 
     <asp:TemplateField HeaderText="Business Unit" HeaderStyle-ForeColor="White"> 
      <ItemTemplate> 
       <asp:Label ID ="lblBU" runat="server" Text='<%#Bind ("ReqBU") %>'></asp:Label> 
      </ItemTemplate> 
      <ItemStyle Font-Names="Calibri" /> 
     </asp:TemplateField> 
     <asp:TemplateField HeaderText="Department" HeaderStyle-ForeColor="White"> 
      <ItemTemplate> 
       <asp:Label ID ="lblDept" runat="server" Text='<%#Bind ("ReqDept") %>'></asp:Label> 
      </ItemTemplate> 
      <ItemStyle Font-Names="Calibri" /> 
     </asp:TemplateField> 
     <asp:TemplateField HeaderText="Section" HeaderStyle-ForeColor="White"> 
      <ItemTemplate> 
       <asp:Label ID ="lblsection" runat="server" Text='<%#Bind ("ReqSection") %>'></asp:Label> 
      </ItemTemplate> 
      <ItemStyle Font-Names="Calibri" /> 
     </asp:TemplateField> 
     <asp:TemplateField HeaderText="Status" HeaderStyle-ForeColor="White"> 
      <ItemTemplate> 
       <asp:Label ID ="lblStatus" runat="server" Text='<%#Bind ("TransStatus") %>'></asp:Label> 
      </ItemTemplate> 
      <ItemStyle Font-Names="Calibri" /> 
     </asp:TemplateField> 
     <%--<asp:TemplateField HeaderText=""> 
      <ItemTemplate> 
       <asp:LinkButton ID ="lnkEdit" runat="server" Text="View" PostBackUrl='<%# "Details.aspx?Id=" + Eval("TransactionID") %>'></asp:LinkButton> 
      </ItemTemplate> 
     </asp:TemplateField>--%> 
     <asp:ButtonField CommandName="editRecord" ControlStyle-CssClass="btn btn-info" ButtonType="Button" Text="View" HeaderText="View Request" HeaderStyle-ForeColor="White"> 
     <ControlStyle CssClass ="btn btn-info" />  
     </asp:ButtonField> 
    </Columns> 
    <HeaderStyle BackColor="CornflowerBlue" /> 
</asp:GridView> 
     </ContentTemplate> 
    <Triggers> 
     <asp:AsyncPostBackTrigger ControlID="GridView1" /> 
    </Triggers> 
    </asp:UpdatePanel> 

OF

<div id="editModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true"> 
    <div class="modal-dialog"> 
     <div class="modal-content"> 
      <div class="modal-header"> 
       <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button> 
       <h3 id="editModalLabel">View Details</h3> 
      </div>  
<asp:UpdatePanel ID="upEdit" runat="server"> 
    <ContentTemplate> 
     <div class ="modal-body"> 
      <table class="table"> 
       <tr> 
        <td>Item ID: 
         <asp:TextBox ID="txtID" runat="server"></asp:TextBox> 
        </td> 
       </tr> 
       <tr> 
        <td>Type: 
         <asp:TextBox ID="txtType" runat="server"></asp:TextBox> 
        </td> 
       </tr> 
       <tr> 
        <td>Model: 
         <asp:TextBox ID="txtModel" runat="server"></asp:TextBox> 
        </td> 
       </tr> 
       <tr> 
        <td>Requested Quantity: 
         <asp:TextBox ID="txtQuan" runat="server"></asp:TextBox> 
        </td> 
       </tr> 
       <tr> 
        <td>Unit: 
         <asp:TextBox ID="txtUnit" runat="server"></asp:TextBox> 
        </td> 
       </tr> 
       <tr> 
        <td>Date Needed: 
         <asp:TextBox ID="txtDate" runat="server"></asp:TextBox> 
        </td> 
       </tr> 
       <tr> 
        <td>Description: 
         <asp:TextBox ID="txtDesc" runat="server"></asp:TextBox> 
        </td> 
       </tr> 
      </table> 
     </div> 
     <div class="modal-footer"> 
      <asp:Label ID="lblResult" Visible="false" runat="server"></asp:Label> 
      <asp:Button ID ="btnSave" runat="server" Text="Approve" CssClass="btn btn-primary" OnClick="btnSave_Click" /> 
      <button class="btn btn-info" data-dismiss="modal" aria-hidden="true">Close</button> 
     </div> 
    </ContentTemplate> 
    <Triggers> 
     <asp:AsyncPostBackTrigger ControlID="GridView1" EventName="RowCommand" /> 
     <asp:AsyncPostBackTrigger ControlID ="btnSave" EventName="Click" /> 
    </Triggers> 
</asp:UpdatePanel> 
    </div> 
     </div> 
    </div> 

MARKUPのですか?

ありがとうございます!

+0

AutoPostBack = "true"をテキストボックスに使用しよう –

+0

GridViewコントロールのマークアップを掲示してください –

+0

投稿Denis –

答えて

0

は、私は私の側にあなたの問題を再作成しようとしたが、私のコードでは、私が持っている唯一の大きな違いworking.Theであるように思わある私がScriptManager control.HaveにGridViewEnableCdn="true"上を見てAutoGenerateSelectButton="True"を使用しましたあなたのロジックが何もしていないことに気づくことができるかどうかを見て、なぜあなたのものが動作していないのかを理解してください。背後

コード:

public partial class DisplayGridViewRowInPopup : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     if (!Page.IsPostBack) 
     { 
      GetData(); 
     } 
    } 

    public void GetData() 
    { 
     var p1 = new Product { TransactionID = 1, ItemType = "Type1", ItemModel = "Model1", ItemQuantity = 1, ItemUnit = "Unit1", ItemDate = DateTime.Now, ItemDesc = "Product 1" }; 
     var p2 = new Product { TransactionID = 2, ItemType = "Type2", ItemModel = "Model2", ItemQuantity = 2, ItemUnit = "Unit2", ItemDate = DateTime.Now, ItemDesc = "Product 2" }; 
     GridView1.DataSource = new List<Product> { p1, p2 }; 
     GridView1.DataBind(); 
    } 

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 
    { 
     int i = Convert.ToInt32(e.CommandArgument); 

     GridViewRow gvrow = GridView1.Rows[i]; 
     txtID.Text = gvrow.Cells[1].Text; 
     txtType.Text = gvrow.Cells[2].Text; 
     txtModel.Text = gvrow.Cells[3].Text; 
     txtQuan.Text = HttpUtility.HtmlDecode(gvrow.Cells[4].Text); 
     txtUnit.Text = HttpUtility.HtmlDecode(gvrow.Cells[5].Text); 
     txtDate.Text = HttpUtility.HtmlDecode(gvrow.Cells[6].Text); 
     txtDesc.Text = HttpUtility.HtmlDecode(gvrow.Cells[7].Text); 

     lblResult.Visible = false; 
     string script = "<script type='text/javascript'>$('#editModal').modal('show');</script>"; 
     ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "EditModalScript", script, false); 
    } 
} 

public class Product 
{ 
    public int TransactionID { get; set; } 
    public string ItemType { get; set; } 
    public string ItemModel { get; set; } 
    public int ItemQuantity { get; set; } 
    public string ItemUnit { get; set; } 
    public DateTime ItemDate { get; set; } 
    public string ItemDesc { get; set; } 
} 

.ASPX:

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script> 
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> 
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" /> 
    <title></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
     <asp:ScriptManager ID="ScriptManager1" runat="server" EnableCdn="true"></asp:ScriptManager> 
     <div id="editModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true"> 
      <div class="modal-dialog"> 
       <div class="modal-content"> 
        <div class="modal-header"> 
         <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button> 
         <h3 id="editModalLabel">View Details</h3> 
        </div> 
        <asp:UpdatePanel ID="upEdit" runat="server"> 
         <ContentTemplate> 
          <div class="modal-body"> 
           <table class="table"> 
            <tr> 
             <td>Item ID: 
         <asp:TextBox ID="txtID" runat="server"></asp:TextBox> 
             </td> 
            </tr> 
            <tr> 
             <td>Type: 
         <asp:TextBox ID="txtType" runat="server"></asp:TextBox> 
             </td> 
            </tr> 
            <tr> 
             <td>Model: 
         <asp:TextBox ID="txtModel" runat="server"></asp:TextBox> 
             </td> 
            </tr> 
            <tr> 
             <td>Requested Quantity: 
         <asp:TextBox ID="txtQuan" runat="server"></asp:TextBox> 
             </td> 
            </tr> 
            <tr> 
             <td>Unit: 
         <asp:TextBox ID="txtUnit" runat="server"></asp:TextBox> 
             </td> 
            </tr> 
            <tr> 
             <td>Date Needed: 
         <asp:TextBox ID="txtDate" runat="server"></asp:TextBox> 
             </td> 
            </tr> 
            <tr> 
             <td>Description: 
         <asp:TextBox ID="txtDesc" runat="server"></asp:TextBox> 
             </td> 
            </tr> 
           </table> 
          </div> 
          <div class="modal-footer"> 
           <asp:Label ID="lblResult" Visible="false" runat="server"></asp:Label> 
           <asp:Button ID="btnSave" runat="server" Text="Approve" CssClass="btn btn-primary" /> 
           <button class="btn btn-info" data-dismiss="modal" aria-hidden="true">Close</button> 
          </div> 
         </ContentTemplate> 
         <Triggers> 
          <asp:AsyncPostBackTrigger ControlID="GridView1" EventName="RowCommand" /> 
          <asp:AsyncPostBackTrigger ControlID="btnSave" EventName="Click" /> 
         </Triggers> 
        </asp:UpdatePanel> 
       </div> 
      </div> 
     </div> 
     <asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
      <ContentTemplate> 
       <asp:GridView ID="GridView1" runat="server" OnRowCommand="GridView1_RowCommand" AutoGenerateSelectButton="True"> 
       </asp:GridView> 
      </ContentTemplate> 
      <Triggers> 
      <asp:AsyncPostBackTrigger ControlID="GridView1" /> 
     </Triggers> 
     </asp:UpdatePanel> 
    </form> 
</body> 
</html> 

出力:

Displaying GridView row edit template in modal popup

+0

こんにちはデニス、それはあなたのデータがプリロードされているため多分あなたのために働いた?私のデータはデータベースから来てバインドします –

+0

これは問題ではありません。if(!Page.IsPostBack)を使用してデータを一度バインドすることを確認してください。データベースにバインドする場合や、このコンテキストではデータの静的リスト –

+0

私はあなたに私のプロジェクトを送ることができますか?もしあなたと一緒に大丈夫なら –

関連する問題