我正在为我的公司开发一个基于网络的安全建议计划,员工可以在其中提交他们拥有的任何安全建议。现在,我正在研究这个系统的管理部分。管理员将能够查看表格中列出的所有安全建议。在表格的最后一列中,将列出状态。当管理员单击其中一个建议的状态时,将出现一个新的弹出窗口 (asp.net ajax ModalPopUpExtender),其中列出所有可能的状态,例如:已执行、已批准...等。当管理员选择其中一种状态,建议的状态将在数据库中更新。我写了代码,但它仍然没有更新建议的状态,所以你能帮我修改它吗?
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>
代码隐藏:
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 SafetySuggestionsStatus SET ID= @statusID";
using (SqlConnection conn = new SqlConnection(connString))
{
conn.Open();
//using (SqlCommand cmd = new SqlCommand(cmdText, conn))
using (SqlCommand cmd = new SqlCommand(updateCommand, conn))
{
cmd.Parameters.AddWithValue("@ID", statusID);
cmd.ExecuteNonQuery();
}
}
SendSuggestionStatusToUser(statusID);
}
更新:
仅供参考,我有以下数据库设计:
Employee Table: Username, Name...
SafetySuggestionsLog: ID, Title, Description, Username, StatusID
SafetySuggestionsStatus: ID, Status
我收到以下错误: