[英]When exporting gridview to xls, the entire row is formatted. How can I limit this to my gridview columns
[英]How can I delete entire row in my SQL datagridview?
如何在datagridview中删除整行。.我在datagrid中已经有一个删除链接。.这是我在vb中的标记代码
<asp:GridView ID="EmployeeHallway" runat="server" AutoGenerateColumns="False" AutoGenerateDeleteButton="False" AutoGenerateSelectButton="True" Height="93px" HorizontalAlign="Center" PageSize="6" style="margin-bottom: 0px; text-align: center;" Width="768px">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<%--ADD THE DELETE LINK BUTTON--%>
<asp:LinkButton ID="LinkButton2" Runat="server" OnClientClick ="return confirm('Are you sure you?');"
CommandName="Delete">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="EmployeeID" HeaderText="Locker ID" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="EmployeeNo" HeaderText="EmployeeNo" />
<asp:BoundField DataField="Email" HeaderText="Email" />
<asp:BoundField DataField="Location" HeaderText="Location" />
</Columns>
<HeaderStyle BackColor="#003366" BorderColor="#336699" BorderStyle="Solid" ForeColor="White" />
<PagerStyle BackColor="#003366" BorderColor="#336699" ForeColor="White" />
<RowStyle BackColor="White" ForeColor="#003366" />
<SelectedRowStyle BackColor="White" ForeColor="#6600FF" />
<SortedAscendingCellStyle BackColor="#CCCCCC" />
</asp:GridView>
当我单击删除链接时,将显示此错误
“ GridView'EmployeeHallway'引发了未处理的事件RowDeleting。”
谁能帮我下一步做什么
您正在使用Delete
作为Delete
链接的CommandName
,因此它将自动创建RowDeleting
事件。 因此,您必须像这样实现它:
您必须添加OnRowDeleting
事件,如下所示:
<asp:GridView ID="EmployeeHallway" runat="server" AutoGenerateColumns="False" AutoGenerateDeleteButton="False" AutoGenerateSelectButton="True" Height="93px" HorizontalAlign="Center" PageSize="6" style="margin-bottom: 0px; text-align: center;" Width="768px">
<RowStyle ForeColor="#003399" HorizontalAlign="Center" OnRowDeleting="EmployeeHallway_RowDeleting"/>
而在后面的代码中:
Public Sub EmployeeHallway_RowDeleting(sender As Object, e As GridViewDeleteEventArgs)
End Sub
在aspx页面中添加OnRowDeleting="OnRowDeleting"
将数据表保存在ViewState("dt")
,然后执行以下操作:
Protected Sub OnRowDeleting(sender As Object, e As GridViewDeleteEventArgs)
Dim index As Integer = Convert.ToInt32(e.RowIndex)
Dim dt As DataTable = TryCast(ViewState("dt"), DataTable)
dt.Rows(index).Delete()
ViewState("dt") = dt
BindGrid()
End Sub
Protected Sub BindGrid()
EmployeeHallway.DataSource = TryCast(ViewState("dt"), DataTable)
EmployeeHallway.DataBind()
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.