我的数据没有显示后点击编辑按钮从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正确吗?如何将数据传输到模态进行编辑。谢谢你!
当你有一个UpdatePanel
扭曲你的代码和你的代码不工作后,你需要做两次思考找到问题。
- 临时删除
UpdatePanel
并重复您所做的,看看问题是否在您的代码后面。 - 放回
UpdatePanel
,打开浏览器的javascript控制台,检查javascript错误。