【问题标题】:data not showing in modal from gridview数据未从gridview以模态显示
【发布时间】:2016-06-29 06:50:55
【问题描述】:

单击 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 是否正确?如何将数据传输到模态进行编辑。谢谢!

【问题讨论】:

  • 这样试试 var clickedRow = clickedButton.NamingContainer as GridViewRow; var clickedUserName = clickedRow.Cells[0].Text;

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


【解决方案1】:

当您有一个 UpdatePanel 扭曲您的代码并且您的代码在回发后无法正常工作时,您需要做两次思考才能找到问题。

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

【讨论】:

    猜你喜欢
    • 2020-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-23
    相关资源
    最近更新 更多