ASP.NET - 如何删除 GridView 的一行?
<asp:GridView ID="gridInboxMessage" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" DataSourceID="LinqDataSource1"
OnSelectedIndexChanged="gridInboxMessage_SelectedIndexChanged">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button runat="server" ID="DeleteInbox" Text="delete" />
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowSelectButton="True" SelectText="show text" />
<asp:BoundField DataField="Title" HeaderText="title" ReadOnly="True" SortExpression="Title" />
<asp:TemplateField SortExpression="Body" HeaderText="body">
<ItemTemplate>
<asp:Label ID="MyBody" runat="server" Text='<%# TruncateText(Eval("Body"))%>'>
</asp:Label>
<asp:Label ID="fullBodyRecieve" Visible="false" runat="server" Text='<%# Eval("Body")%>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="Sender" HeaderText="sender">
<ItemTemplate>
<asp:Label ID="sender" runat="server" Text='<%# GetCompanyNameById(Eval("Sender"))%>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="Date1" HeaderText="date">
<ItemTemplate>
<asp:Label ID="PersianDateRecieve" runat="server" Text='<%# GetPersianDate(Eval("Date1"))%>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<AlternatingRowStyle BackColor="orange" />
</asp:GridView>
<div id="contentBodyMessageRecieve" style="width:300px; border:1px silid black" runat="server">
</div>
<asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="DataClassesDataContext" Select="new (Title, Body, Sender, Date1)" TableName="PrivateMessages" Where="Receptor == @Receptor">
<WhereParameters>
<asp:QueryStringParameter Name="Receptor" QueryStringField="idCompany" Type="String" />
</WhereParameters>
</asp:LinqDataSource>
</fieldset>
<br />
<br />
我希望当用户单击 DeleteBox
时删除该行。
<asp:GridView ID="gridInboxMessage" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" DataSourceID="LinqDataSource1"
OnSelectedIndexChanged="gridInboxMessage_SelectedIndexChanged">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button runat="server" ID="DeleteInbox" Text="delete" />
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowSelectButton="True" SelectText="show text" />
<asp:BoundField DataField="Title" HeaderText="title" ReadOnly="True" SortExpression="Title" />
<asp:TemplateField SortExpression="Body" HeaderText="body">
<ItemTemplate>
<asp:Label ID="MyBody" runat="server" Text='<%# TruncateText(Eval("Body"))%>'>
</asp:Label>
<asp:Label ID="fullBodyRecieve" Visible="false" runat="server" Text='<%# Eval("Body")%>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="Sender" HeaderText="sender">
<ItemTemplate>
<asp:Label ID="sender" runat="server" Text='<%# GetCompanyNameById(Eval("Sender"))%>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="Date1" HeaderText="date">
<ItemTemplate>
<asp:Label ID="PersianDateRecieve" runat="server" Text='<%# GetPersianDate(Eval("Date1"))%>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<AlternatingRowStyle BackColor="orange" />
</asp:GridView>
<div id="contentBodyMessageRecieve" style="width:300px; border:1px silid black" runat="server">
</div>
<asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="DataClassesDataContext" Select="new (Title, Body, Sender, Date1)" TableName="PrivateMessages" Where="Receptor == @Receptor">
<WhereParameters>
<asp:QueryStringParameter Name="Receptor" QueryStringField="idCompany" Type="String" />
</WhereParameters>
</asp:LinqDataSource>
</fieldset>
<br />
<br />
i want when user click on DeleteBox
delete that row.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 RowCommand 事件。
当单击 GridView 控件中的按钮时,将引发 RowCommand 事件。这使您能够提供一个事件处理方法,每当此事件发生时,该方法都会执行自定义例程。
GridView 控件中的按钮还可以调用该控件的一些内置功能。要执行其中一项操作,请将按钮的 CommandName 属性设置为下表中的值之一。
GridView 行命令
Use RowCommand Event.
The RowCommand event is raised when a button is clicked in the GridView control. This enables you to provide an event-handling method that performs a custom routine whenever this event occurs.
Buttons within a GridView control can also invoke some of the built-in functionality of the control. To perform one of these operations, set the CommandName property of a button to one of the values in the following table.
GridView row command