0

私は新しい ASP.NET 開発者で、従業員が安全に関する提案を送信できる Web ベースの提案ボックス プログラムを開発しています。現在、私はこのシステムの管理部分に取り組んでいます。

管理者は、GridView コントロールにリストされているすべての提案を表示できます。GridView の最後の列に、ステータスが表示されます。管理者がこれらの提案のいずれかのステータスをクリックすると、新しいポップアップ ウィンドウ (asp.net ajax ModalPopUpExtender) が表示され、アクション済み、承認済みなど、考えられるすべてのステータスが一覧表示されます。これらのステータスのいずれかを選択すると、提案のステータスがデータベースで更新されます。コードを書きましたが、それでも提案のステータスが更新されません。

それを修正するのを手伝ってもらえますか?

参考までに、次のデータベース設計があります。

Employee Table: Username, Name...
SafetySuggestionsLog: ID, Title, Description, Username, StatusID
SafetySuggestionsStatus: ID, Status

ASP.NET コード:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
                        AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ID" 
                        width="900px" CssClass="mGrid" 
                        DataSourceID="SqlDataSource1" 
                        OnRowDataBound="GridView1_RowDataBound">
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" CssClass="alt" />
            <HeaderStyle Font-Bold = "True" ForeColor="Black" Height="20px"/> 
            <Columns>
                <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" 
                    ReadOnly="True" SortExpression="ID" />
                <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                <asp:BoundField DataField="Description" HeaderText="Description" 
                    SortExpression="Description" />
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                <asp:BoundField DataField="Username" HeaderText="Username" 
                    SortExpression="Username" />
                <asp:BoundField DataField="DivisionShortcut" HeaderText="DivisionShortcut" 
                    SortExpression="DivisionShortcut" />
                <asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" />

                <%-- This to make status be opened and edited through the Ajax ModalPopUp Window --%>
                <asp:TemplateField HeaderText="Status">
                    <ItemTemplate>
                        <asp:LinkButton runat="server" ID="lnkSuggestionStatus" Text='<%#Eval("Status")%>'
                                        OnClick="lnkSuggestionStatus_Click">
                        </asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>

                <%--<asp:HyperLinkField HeaderText="Status" 
                    SortExpression="Status" />--%>
            </Columns>
            <RowStyle HorizontalAlign="Center" />
        </asp:GridView>

        <asp:Button runat="server" ID="btnModalPopUp" style="display:none" />

        <AjaxToolkit:ModalPopUpExtender ID="modalPopUpExtender1"
                                        runat="server" 
                                        TargetControlID="btnModalPopUp" 
                                        PopupControlID="pnlPopUp" 
                                        BackgroundCssClass="popUpStyle"
                                        PopupDragHandleControlID="panelDragHandle" 
                                        OkControlID="OKButton">
        </AjaxToolkit:ModalPopUpExtender>

        <asp:Panel runat="server" ID="pnlPopUp">

                    <asp:RadioButtonList ID="StatusList" runat="server" RepeatColumns="1" RepeatDirection="Vertical"
                                            RepeatLayout="Table" TextAlign="Left" DataSourceID="SuggestionStatusDataSource"
                                            DataTextField="Status" DataValueField="ID">
                        <asp:ListItem id="option1" runat="server" Value="ACTIONED" />
                        <asp:ListItem id="option2" runat="server" Value="APPROVED" />
                        <asp:ListItem id="option3" runat="server" Value="PENDING" />
                        <asp:ListItem id="option4" runat="server" Value="TRANSFERRED" />
                    </asp:RadioButtonList>
                    <asp:SqlDataSource ID="SuggestionStatusDataSource" runat="server"
                                        ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
                                        SelectCommand="SELECT * FROM [SafetySuggestionsStatus]"></asp:SqlDataSource>

                    <asp:Button ID="confirmButton" runat="server" Text="Confirm" 
                                OnClientClick="javascript:return confirm('Are you sure you want to send an email notification about the safety suggestion to the owner?')" 
                                OnClick="btnSendStatus_Click" />

            <asp:Button ID="OKButton" runat="server" Text="Close" />
        </asp:Panel>
        </ContentTemplate>
        </asp:UpdatePanel>

コード ビハインド:

protected void lnkSuggestionStatus_Click(object sender, EventArgs e)
    {
        LinkButton lnkSuggestionStatus = sender as LinkButton;

        //var safetySuggestionsId = 

        //get reference to the row selected 
        GridViewRow gvrow = (GridViewRow)lnkSuggestionStatus.NamingContainer;

        //set the selected index to the selected row so that the selected row will be highlighted
        GridView1.SelectedIndex = gvrow.RowIndex;

        //This HiddenField used to store the value of the ID
        HiddenField1.Value = gvrow.RowIndex.ToString();

        //show the modalPopUp
        modalPopUpExtender1.Show();
    }

    public void btnSendStatus_Click(object sender, EventArgs e) {

        var statusID = StatusList.SelectedValue;

        string connString = "Data Source=localhost\\sqlexpress;Initial Catalog=psspdbTest;Integrated Security=True";
        //For updating the status of the safety suggestion
        string updateCommand = "UPDATE SafetySuggestionsLog SET StatusID= @statusID where ID=@SafetySuggestionsID";
        using (SqlConnection conn = new SqlConnection(connString))
        {
            conn.Open();
            using (SqlCommand cmd = new SqlCommand(updateCommand, conn))
            {
                cmd.Parameters.AddWithValue("@statusID", Convert.ToInt32(statusID));
                cmd.Parameters.AddWithValue("@SafetySuggestionsID", Convert.ToInt32(HiddenField1.Value));
                cmd.ExecuteNonQuery();
            }
            //reset the value of hiddenfield
            HiddenField1.Value = "-1";
        }

        GridView1.DataBind();

        //SendSuggestionStatusToUser(statusID);
    }

エラーにはなりませんでしたが、ModalPopUp ウィンドウで選択したステータスが GridView に反映されません。なんで?

4

1 に答える 1

0

btnSendStatus_Click で、データベースを更新しますが、グリッドビューは更新しません。置く必要があるようです

    gridview.databind()

その関数の最後に。

更新パネルにトリガーを追加すると役立つかもしれません

    </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="OKButton" EventName="click" />
        </Triggers>
</asp:UpdatePanel>

それが役立つことを願っています

于 2012-07-03T12:47:21.227 に答える