【问题标题】:website gridview not working at iis on azure网站 gridview 在 iis on azure 上不起作用
【发布时间】:2017-09-19 07:10:17
【问题描述】:

大家好,我在 azure 上发布已发布的网络应用时遇到问题

所以,我的代码是两页,一页用于数据列表,另一页用于输入页

有问题的页面包含一个带有包含 2 个图像按钮的模板字段的网格视图

一个用于显示块另一个div并填充其中的网格

另一个是重定向到输入页面,并带有一些会话更新以标记事务是新的还是正在编辑的

问题是,我的 gridview_rowcommand 方法可以在本地进行快速调试 (IIS Express) 或通过 IIS 运行

但是当我在 azure 上发布它时,rowcommand 根本不起作用

下面是一些代码

<div class="divWrapperGrid" style="border-top:none;">
                        <div class="divContentGrid" style="min-height:190px;">                
                            <asp:Button ID="btnChange" runat="server" Text="Button" Style="display:none;" OnClick="btnChange_Click"/>
                            <asp:UpdatePanel runat="server" ID="upWHOrder">
                                <ContentTemplate>
                                    <asp:GridView ID="dgWHOrder" runat="server" AutoGenerateColumns="false" AllowPaging="true" ShowHeaderWhenEmpty="true"
                                                    CssClass="data-grid" HeaderStyle-CssClass="data-grid-header" RowStyle-CssClass="data-grid-row" EmptyDataRowStyle-CssClass="data-grid"
                                                    GridLines="None"  EmptyDataText="There is no data"
                                                    OnRowDataBound ="dgWHOrder_RowDataBound" OnRowCommand="dgWHOrder_RowCommand">
                                        <EmptyDataTemplate>
                                            <asp:Label ID="Label2" CssClass="no-data-grid" runat="server">No records found!</asp:Label>
                                        </EmptyDataTemplate>
                                        <Columns>
                                            <asp:TemplateField HeaderStyle-CssClass="hidden-column" ItemStyle-CssClass="hidden-column">
                                                <EditItemTemplate>
                                                    <asp:Label ID="laID" runat="server" Text='<%#Eval("ID")%>'></asp:Label>
                                                </EditItemTemplate>
                                                <ItemTemplate>
                                                    <asp:Label ID="laID" runat="server" Text='<%#Eval("ID")%>'></asp:Label>
                                                </ItemTemplate>                                
                                            </asp:TemplateField>
                                            <asp:BoundField DataField="WarehouseOrderNo" />
                                            <asp:BoundField DataField="OrderDateStr" />
                                            <asp:BoundField DataField="TotalItem" />
                                            <asp:BoundField DataField="Responsible" />                             
                                            <asp:BoundField DataField="MerchantCode" />
                                            <asp:TemplateField ItemStyle-Width="35%" ItemStyle-HorizontalAlign="Right">
                                                <EditItemTemplate>
                                                    <asp:ImageButton ID="btnSave" runat="server" CommandName="save" CommandArgument="<%#((GridViewRow) Container).RowIndex %>" ImageUrl="~/images/save-icon.png" Width="20px" Height="20px" ToolTip="Save" OnClientClick="return true;" /> 
                                                    <asp:ImageButton ID="btnCancel" runat="server" CommandName="cancel" CommandArgument="<%#((GridViewRow) Container).RowIndex %>" ImageUrl="~/images/cancel-icon.png" Width="20px" Height="20px" ToolTip="Cancel" OnClientClick="return true;" />
                                                </EditItemTemplate>
                                                <ItemTemplate>
                                                    <asp:ImageButton ID="btnEdit" runat="server" CommandName="edit" CommandArgument="<%#((GridViewRow) Container).RowIndex %>" ImageUrl="~/images/edit-icon.png" Width="20px" Height="20px" ToolTip="Update" OnClientClick="return true;" /> 
                                                    <asp:ImageButton ID="btnView" runat="server" CommandName="view" CommandArgument="<%#((GridViewRow) Container).RowIndex %>" ImageUrl="~/images/delete-xxl.png" Width="20px" Height="20px" ToolTip="View" OnClientClick="return true;" />
                                                </ItemTemplate>
                                            </asp:TemplateField>   
                                        </Columns>
                                    </asp:GridView>
                                </ContentTemplate>
                            </asp:UpdatePanel>
                        </div>
                    </div>

btnEdit 是重定向处理之一 btnView 用于视图处理一个

以及gridview_rowcommand方法

protected void dgWHOrder_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int rowIndex = 0;
            rowIndex = Convert.ToInt32(e.CommandArgument);

            string script = string.Empty;
            int HeaderID = 0;

            if (rowIndex > -1)
            {
                GridViewRow row = (GridViewRow)(((ImageButton)e.CommandSource).NamingContainer);
                HeaderID = Convert.ToInt32(((Label)row.FindControl("laID")).Text);
            }

            BPWarehouseOrder objBP = new BPWarehouseOrder();
            BOSearch objSrc = new BOSearch();

            switch (e.CommandName)
            {
                case "edit":
                    IsEdit = true;
                    EditItemHeader = (from a in ListHeader
                                      where a.ID == HeaderID
                                      select a).Single();
                    Response.Redirect("WarehouseOrderIns.aspx");
                    break;
                case "view":
                    List<BOWarehouseOrderDatail> objDt = new List<BOWarehouseOrderDatail>();
                    objBP = new BPWarehouseOrder();

                    objSrc = new BOSearch();
                    objSrc.FieldName = "IDWarehouseOrder";
                    objSrc.FieldValue = HeaderID.ToString();
                    objSrc.SearchType = "Equal";

                    objDt = objBP.GetDetailList(objSrc);
                    if (objBP.MsgCode != 0)
                    {
                        script += " alert('" + objBP.MsgDesc + @"');
                                  ";

                        ScriptManager.RegisterClientScriptBlock(this, GetType(), Guid.NewGuid().ToString(), script, true);
                        return;
                    }

                    dgOrderDetail.DataSource = objDt;
                    if (objDt.Count > 0)
                    {
                        dgOrderDetail.PageSize = objDt.Count;
                    }
                    dgOrderDetail.DataBind();

                    script += @" document.getElementById('popup').style.display = 'block';
                               ";
                    ScriptManager.RegisterClientScriptBlock(this, GetType(), Guid.NewGuid().ToString(), script, true);
                    break;
            }
        }

TLDR:在 azure 发布网站,gridview_rowcommand 函数在 azure 不工作,但在本地工作

问候

普通程序员

【问题讨论】:

标签: c# asp.net azure iis gridview


【解决方案1】:

我在 UpdatePanel 控件中使用 ASP.NET GridView 控件创建了以下示例,它在我的 Azure Web 应用服务上运行良好,GridView 控件的OnRowCommand 可以按预期执行。

UpdatePanel 中的 GridView

<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <div>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:GridView ID="my_testgrid" runat="server" AutoGenerateColumns="false" OnRowCommand="my_testgrid_RowCommand">
                    <Columns>
                        <asp:TemplateField HeaderText="ID">
                            <ItemTemplate>
                                <asp:Label runat="server" Text='<%#Eval("ID")%>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Name">
                            <ItemTemplate>
                                <asp:Label runat="server" Text='<%#Eval("Name")%>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:Button ID="Button1" runat="server" Text="select" CommandName="select" CommandArgument="<%#((GridViewRow) Container).RowIndex %>" />
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
</form>

在 Page_Load 事件中指定数据源

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("ID");
        dt.Columns.Add("Name");

        dt.Rows.Add("u001", "jack");
        dt.Rows.Add("u002", "fred");

        my_testgrid.DataSource = dt;
        my_testgrid.DataBind();
    }
}

OnRowCommand 事件

protected void my_testgrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "select")
    {
        string arg = e.CommandArgument.ToString();
    }
}

浏览网络应用

点击[选择]按钮可以执行OnRowCommand事件

要解决问题,您可以尝试remote debug your web app 并检查您的代码是否有问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-07
    • 2016-03-21
    • 2015-10-06
    • 1970-01-01
    • 2016-10-26
    • 1970-01-01
    • 2011-05-20
    • 1970-01-01
    相关资源
    最近更新 更多