2016-06-29 21 views
0

Gridviewから編集ボタンをクリックしてもデータが表示されません。ここ データがgridviewからモーダルで表示されない

は私のGridViewのコード

<asp:UpdatePanel ID ="panel1" runat="server"> 
     <ContentTemplate> 
    <asp:GridView ID="gv1" runat="server" AutoGenerateColumns="false" DataKeyNames="ID" AllowPaging="true" OnRowCommand="gv1_RowCommand" CellPadding="4" HeaderStyle-BackColor="CornflowerBlue" BorderWidth="5" BorderColor="CornflowerBlue" Width="100%" CssClass="table table-hover"> 
     <Columns> 
      <asp:TemplateField HeaderText ="ID"> 
       <ItemTemplate> 
        <asp:Label ID="lblID" runat="server" Text='<%#Bind ("ID") %>'></asp:Label> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField HeaderText ="Type"> 
       <ItemTemplate> 
        <asp:Label ID="lbltype" runat="server" Text='<%#Bind ("ItemType") %>'></asp:Label> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField HeaderText ="Model"> 
       <ItemTemplate> 
        <asp:Label ID="lblModel" runat="server" Text='<%#Bind ("ItemModel") %>'></asp:Label> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField HeaderText ="Quantity"> 
       <ItemTemplate> 
        <asp:Label ID="lblQuan" runat="server" Text='<%#Bind ("ItemQuantity") %>'></asp:Label> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField HeaderText ="Unit"> 
       <ItemTemplate> 
        <asp:Label ID="lblUnit" runat="server" Text='<%#Bind ("ItemUnit") %>'></asp:Label> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField HeaderText ="Target Date"> 
       <ItemTemplate> 
        <asp:Label ID="lblDate" runat="server" Text='<%#Bind ("ItemDate") %>'></asp:Label> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField HeaderText ="Description"> 
       <ItemTemplate> 
        <asp:Label ID="lblDesc" runat="server" Text='<%#Bind ("ItemDesc") %>'></asp:Label> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField HeaderText ="Remarks"> 
       <ItemTemplate> 
        <asp:Label ID="lblRem" runat="server" Text='<%#Bind ("ItemRemarks") %>'></asp:Label> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:ButtonField CommandName="editRecord" ControlStyle-CssClass="btn btn-info" ButtonType="Button" Text="Edit" HeaderText="Edit"> 
       <ControlStyle CssClass="btn btn-info" /> 
       </asp:ButtonField> 
      <%--<asp:TemplateField HeaderText ="Status"> 
       <ItemTemplate> 
        <asp:Label ID="lblStat" runat="server" Text='<%#Bind ("ItemStatus") %>'></asp:Label> 
        <asp:DropDownList ID ="ddlStat" runat="server"></asp:DropDownList> 
       </ItemTemplate> 
      </asp:TemplateField>--%> 
     </Columns> 
    </asp:GridView> 
      </ContentTemplate> 
     <Triggers> 
     </Triggers> 
     </asp:UpdatePanel> 

であり、ここでは.cs

int index = Convert.ToInt32(e.CommandArgument); 
     //if(e.CommandName.Equals("editRecord")) 
     //{ 

      GridViewRow gvrow = gv1.Rows[index]; 
      lblIDs.Text = HttpUtility.HtmlDecode(gvrow.Cells[0].Text).ToString() ; 
      lblitemTypes.Text = HttpUtility.HtmlDecode(gvrow.Cells[1].Text).ToString(); 
      lblModels.Text = HttpUtility.HtmlDecode(gvrow.Cells[2].Text).ToString(); 
      lblQuans.Text = HttpUtility.HtmlDecode(gvrow.Cells[3].Text).ToString(); 
      lblUnits.Text = HttpUtility.HtmlDecode(gvrow.Cells[4].Text).ToString(); 
      lblDates.Text = HttpUtility.HtmlDecode(gvrow.Cells[5].Text).ToString(); 
      lblDescs.Text = HttpUtility.HtmlDecode(gvrow.Cells[6].Text).ToString(); 
      lblRemarkss.Text = HttpUtility.HtmlDecode(gvrow.Cells[7].Text).ToString(); 
      //ddlStat.Text = HttpUtility.HtmlDecode(gvrow.Cells[8].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); 

ページが通過しますが、それはGridViewのデータを表示するdoesntのための私のコードですが、私は入れてみましたブレークポイントと私はそれが何か内部にanyvalue持っていない参照してください、私のエラーは何ですか? HttpUtility.HtmlDecodeは正しいですか?どのように私は編集のためにモーダルにデータを転送することができます。ありがとうございました!

+0

このようにしてくださいvar clickedRow = clickedButton.NamingContainer as GridViewRow; var clickedUserName = clickedRow.Cells [0] .Text; –

答えて

0

UpdatePanelコードをワープして、ポストバック後にコードが機能しないときは、問題を見つけるために2つの考えをする必要があります。

  1. 一時的にUpdatePanelを削除して、あなたのやり方を繰り返し、問題がコードの背後にあるかどうかを確認します。
  2. UpdatePanelを置き、ブラウザのJavaScriptコンソールを開いてJavaScriptのエラーを確認してください。
関連する問題