根据点击的按钮更新字段

时间:2014-10-17 01:52:19

标签: asp.net sql-server

我有3个ASPLink按钮:已解决,未解决,已取消

我希望能够根据单击的按钮更改ResolutionStatusID字段。我不确定该怎么做。

即。

单击Unresolved按钮时,ResolutionStatusID = 3的值

单击“已取消”按钮时,ResolutionStatusID = 4的值

单击“已解决”按钮时,ResolutionStatusID = 5的值

以下代码

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" 
    DeleteCommand="DELETE FROM [HardwareFault] WHERE [HardwareFaultID] = @HardwareFaultID" 
    InsertCommand="INSERT INTO [HardwareFault] ([FaultTitle], [ResolutionStatusID], [Message], [LoggedBy], [DateTimeLogged]) VALUES (@FaultTitle, @ResolutionStatusID, @Message, @LoggedBy, @DateTimeLogged)" 
    SelectCommand="SELECT dbo.ResolutionStatus.ResolutionName, dbo.HardwareFault.*, dbo.aspnet_Users.UserId, dbo.aspnet_Users.UserName FROM dbo.HardwareFault LEFT OUTER JOIN dbo.aspnet_Users ON dbo.HardwareFault.LoggedBy = dbo.aspnet_Users.UserId LEFT OUTER JOIN dbo.ResolutionStatus ON dbo.HardwareFault.ResolutionStatusID = dbo.ResolutionStatus.ResolutionStatusID WHERE [HardwareID] = @HardwareID" 
    UpdateCommand="UPDATE [HardwareFault] SET [ResolutionStatusID] = @ResolutionStatusID WHERE [HardwareFaultID] = @HardwareFaultID">



    <DeleteParameters>
        <asp:Parameter Name="HardwareFaultID" Type="Int32" />
    </DeleteParameters>
    <SelectParameters>
            <asp:QueryStringParameter DefaultValue="1" Name="HardwareID" QueryStringField="HardwareID" />
    </SelectParameters>
    <InsertParameters>
        <asp:Parameter Name="FaultTitle" Type="String" />
        <asp:Parameter Name="ResolutionStatusID" Type="Int32" />
        <asp:Parameter Name="Message" Type="String" />
        <asp:Parameter Name="LoggedBy" Type="String" />
        <asp:Parameter Name="DateTimeLogged" Type="DateTime" />
    </InsertParameters>
    <UpdateParameters>
        <asp:Parameter Name="ResolutionStatusID" Type="Int32" />
    </UpdateParameters>
</asp:SqlDataSource>


<div>

<asp:ListView ID="ListView1" runat="server" DataKeyNames="HardwareFaultID" DataSourceID="SqlDataSource1">

    <ItemTemplate>
        <tr style=""class="<%# Eval("ResolutionName") %>">

            <td>

                <div class="btn-group">
                    <a class="btn btn-mini dropdown-toggle" style="text-decoration:none; padding:3px 6px 3px 5px;" href="#" data-toggle="dropdown" title="Change Status">
                        <span class="icon16 icomoon-icon-cog-2" style="padding-top:7px;"></span>
                        <span class="caret" style="margin-top:10px;"></span>
                    </a>
                    <ul class="dropdown-menu" style="top: 33px; left: -75px; min-width: 110px; font-size: 12px;">

                        <li>
                                <asp:LinkButton ID="Resolved" OnClientClick="javascript:return confirm('Are you sure you want to change this fault to Resolved?');" runat="server" CssClass="miniDropdown">Resolved <span class="btn btn-success icon16 icomoon-icon-checkmark-2" style="text-decoration:none; padding:3px 6px 7px 5px;"></span></asp:LinkButton>
                        </li>
                        <li>
                                <asp:LinkButton ID="Unresolved" OnClientClick="javascript:return confirm('Are you sure you want to change this fault to Unresolved?');" runat="server" CssClass="miniDropdown">Unresolved <span class="btn btn-info icon16 typ-icon-question" style="text-decoration:none; padding:3px 6px 7px 5px;"></span></asp:LinkButton>
                        </li>
                        <li>
                                <asp:LinkButton ID="Cancel" OnClientClick="javascript:return confirm('Are you sure you want to Cancel this fault?');" runat="server" CssClass="miniDropdown" CommandName="Update">Cancelled <span class="btn btn-danger icon16 icomoon-icon-blocked" style="text-decoration:none; padding:3px 6px 7px 5px;"></span></asp:LinkButton>
                        </li>
                    </ul>
                </div>
            </td>
        </tr>
    </ItemTemplate>

</asp:ListView>

</div>

2 个答案:

答案 0 :(得分:0)

我认为您应该找到listview链接按钮的控件并执行您想要的任何操作

在asp页面

 <asp:LinkButton ID="simjoblin" runat="server" OnClick="simjoblin_Click" CommandName='<%# Eval("ID")%>' class="ns_empoptions ns_similrjobs">

在c#page

protected void simjoblin_Click(object sender, EventArgs e)
{
    LinkButton jid = sender as LinkButton;
    string jobid = jid.CommandName;
//do what you want

}

希望这会对你有所帮助

答案 1 :(得分:0)

您可以使用listview的项目命令功能。添加 OnItemCommand 事件,并将 CommandName ='...' CommandArgument ='&lt;%#Eval(“ID”)%&gt;'在你的LinkBut​​tons。

<asp:ListView OnItemCommand="ListView1_ItemCommand1">
    <ItemTemplate>
        <asp:LinkButton CommandName='Resolved' CommandArgument='<%# Eval("ID")%>' ID="Resolved"></asp:LinkButton>
        <asp:LinkButton CommandName='Unresolved' CommandArgument='<%# Eval("ID")%>' ID="Unresolved"></asp:LinkButton>
        <asp:LinkButton CommandName='Cancel' CommandArgument='<%# Eval("ID")%>' ID="Cancel"></asp:LinkButton>
    </ItemTemplate>
</asp:ListView>

C#代码(决定 e.CommandName ):

protected void ListView1_ItemCommand1(object sender, ListViewCommandEventArgs e)
{
    switch (e.CommandName)
    {
        case "Resolved":
            // do sth
            break;
        case "Unresolved":
            // do sth
            break;
        case "Cancel":
            // do sth
            break;
        default:
            break;
    }
}