数据未显示在gridview中的模态中

时间:2016-06-29 06:50:55

标签: c# jquery asp.net gridview modal-dialog

单击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中的数据,我试图设置一个断点,我发现它里面没有任何值,我的错误是什么? HttpUtility.HtmlDecode是正确的吗?如何将数据传输到模态进行编辑。谢谢!

1 个答案:

答案 0 :(得分:0)

如果你的代码有UpdatePanel变形,并且你的代码在回复后不起作用,你需要做两个想法才能找到问题。

  1. 临时删除UpdatePanel并重复您的操作,并查看问题是否在您的代码背后。
  2. 放回UpdatePanel并打开浏览器的javascript控制台并检查javascript错误。