【发布时间】:2021-03-19 12:17:16
【问题描述】:
我有一个 GridView,通过它我可以显示一些书籍的详细信息,并且可以根据书籍属性对其进行过滤。问题是,如果我过滤一些书并尝试编辑其中一本,编辑器会选择整体行值的 id 而不是新的。 var id = Convert.ToInt32(gridview.Rows[e.NewEditIndex].Cells[1].Text);我通过这个获取索引值
<div class="col">
<asp:GridView OnRowEditing="GridView2_RowEditing" OnRowUpdating="GridView3_RowUpdating" OnRowCancelingEdit="GridView3_RowCancelingEdit"
class="table table-striped table-bordered" ID="GridView3" runat="server" AutoGenerateColumns="false" DataKeyNames="Id"
HeaderStyle-BackColor="#95daa4" HeaderStyle-ForeColor="Black" >
<Columns >
<asp:CommandField ShowEditButton="true" ControlStyle-Width="26px" ControlStyle-CssClass="linkGVE"/>
<asp:BoundField DataField="Id" HeaderText="ID" ReadOnly="True" SortExpression="Id">
<ControlStyle Font-Bold="True" CssClass="linkGVE"/>
<ItemStyle Font-Bold="True"/>
</asp:BoundField>
<asp:TemplateField >
<ItemTemplate>
<div class="container-fluid">
<div class="col-lg-10">
<div class="row">
<div class="col-12">
<asp:Label ID="Label1" runat="server" class="animated bounceInRight" Text='<%# Eval("BookName") %>' Font-Bold="True" Font-Size="18px"></asp:Label>
</div>
</div>
<br/>
<div class="row">
<div class="col-12">
<span>
<b>Province -</b><span> </span>
<asp:Label ID="Label4" runat="server" Text='<%# Eval("Province") %>'></asp:Label>
</span>
</div>
</div>
<div class="row">
<div class="col-12">
<b>Subject - </b>
<asp:Label ID="Label5" runat="server" Text='<%# Eval("Subject") %>'> </b></asp:Label>
| <b>Categories -</b>
<asp:Label ID="Label6" runat="server" Text='<%# Eval("Categorey") %>'></asp:Label>
| <b>PackageName -</b>
<asp:Label ID="Label7" runat="server" Text='<%# Eval("PackageName") %>'></asp:Label>
</div>
</div>
<div class="row">
<div class="col-12">
<b>CategoricalTitle -</b>
<asp:Label ID="Label12" runat="server" Text='<%# Eval("CategoricalTitle") %>'></asp:Label>
</div>
</div>
</div>
<div class="col-lg-2 " style="margin-top: 25px; text-align: center;">
<asp:Image class="img-fluid" BorderWidth="2px" BorderColor="#82aeb1" ID="Image1" Height="100px" Width="120px" runat="server" ImageUrl='<%# "http://0.0.0.0/Pictures/" + Eval("PictureURL") %>'/>
<a href='<%# "http://0.0.0.0.0/PDF/" + Eval("PDFURL") %>' style="font-size: 11px;color: black">Download</a>
</div>
</div>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
【问题讨论】:
标签: asp.net sorting aspxgridview