Asp.net 未发布gridview回发-VS2008
这是我的aspx:Asp.net 未发布gridview回发-VS2008,asp.net,visual-studio-2008,Asp.net,Visual Studio 2008,这是我的aspx: <asp:UpdatePanel ID="resultPanel" runat="server" UpdateMode="Conditional"> <Triggers> <asp:AsyncPostBackTrigger ControlID="AddDocument" /> </Triggers> <ContentTemplate> <asp:GridView ID="gridView" ru
<asp:UpdatePanel ID="resultPanel" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="AddDocument" />
</Triggers>
<ContentTemplate>
<asp:GridView ID="gridView" runat="server" AutoGenerateColumns="False" EnableSortingAndPagingCallbacks="True"
AllowPaging="True" DataSourceID="FilesObjectDataSource" PageSize="5" OnRowCommand="gridView_RowCommand"
DataKeyNames="FileGuid" HorizontalAlign="Left" Width="100%" BorderStyle="Solid"
BorderColor="Black">
<Columns>
<asp:BoundField DataField="RID" HeaderText="ID" ReadOnly="True"></asp:BoundField>
<asp:BoundField DataField="Category" HeaderText="SubCategory" ReadOnly="True">
</asp:BoundField>
<asp:BoundField DataField="FileTypeName" HeaderText="Type" ReadOnly="True">
</asp:BoundField>
<asp:BoundField DataField="FileGUID" Visible="false" />
<asp:ButtonField Text="X" ButtonType="Button" ItemStyle-Width="20px" CommandName="DelFile">
<ItemStyle Width="20px" />
</asp:ButtonField>
</Columns>
<RowStyle CssClass="RowStyle" />
<EmptyDataRowStyle CssClass="EmptyRowStyle" />
<PagerStyle CssClass="PagerStyle" />
<SelectedRowStyle CssClass="SelectedRowStyle" />
<HeaderStyle CssClass="HeaderStyle" />
<EditRowStyle CssClass="EditRowStyle" />
<AlternatingRowStyle CssClass="AltRowStyle" />
</asp:GridView>
</ContentTemplate>
有时itt会导致未设置对象引用,有时它会起作用。不确定为什么会在生产环境中发生这种情况,而不是在开发和测试环境中。我不确定这是否有什么不同,但在(“FileGuid”)中就是这样 及 不匹配(“文件GUID”)
您可以像这样在row命令事件中访问值
protected void gridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "DelFile")
{
int index = Convert.ToInt32(e.CommandArgument);
int documentID = Convert.ToInt32(gridView.DataKeys[index].Value);
// Write your further code
}
}
DataKeyNames="FileGuid"
fileGuid = new Guid(gridView.DataKeys[rowIndex].Values["FileGuid"].ToString());
<asp:BoundField DataField="FileGUID" Visible="false" />
protected void gridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "DelFile")
{
int index = Convert.ToInt32(e.CommandArgument);
int documentID = Convert.ToInt32(gridView.DataKeys[index].Value);
// Write your further code
}
}