详细信息视图中的自定义按钮更新数据库中的值

发布于 2024-11-29 15:16:55 字数 1428 浏览 2 评论 0原文

我正在尝试练习,并从小游戏开始。用户可以进行注册等操作。

现在我不知道如何让用户“工作”,我有 GridViewDetailsView,在 GridView 用户选择公司,它显示在详细信息视图。在 DetailsView 中,我有带有“工作”标题的自定义按钮。在数据库中,我有默认值为“300 美元”的表。当用户单击 DetailsView 中的自定义按钮“work”时,我想更改数据库中的值,例如 300+400 美元 = 700. 美元。所以新的更新值需要是700。我尝试执行它但找不到解决方案。

我有 .aspx 页面,带有“薪水”标签和自定义按钮。

asp:DetailsView ID="DetailsView1" runat="server".....

<ItemTemplate>
    <asp:Label ID="Label5" runat="server" Text="Salary($):" Font-Size="Small" ForeColor="#9F9B9B"></asp:Label>
    <asp:Label ID="lblSalary" runat="server" Text='<%# Bind("Salary") %>'></asp:Label>
</ItemTemplate>

<asp:TemplateField ShowHeader="False">
    <ItemTemplate>
        <asp:Button ID="BtnWork" runat="server" CausesValidation="false" CommandName="" 
                        Text="Work" OnClick="BtnWork_Click" />
    </ItemTemplate>
</asp:TemplateField>

和 aspx.cs 页面:

protected void BtnWork_Click(object sender, EventArgs e)
{
    MembershipUser currentUser = Membership.GetUser();
    Guid currentUserId = (Guid)currentUser.ProviderUserKey;

    string ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
    string sql = "SELECT * FROM Custon_MoneyWork WHERE UserId=@UserId";
}

I'm trying to practice and started with small game. Users can register and so on.

Now I have no idea how to perform user to "work", I have GridView and DetailsView, in GridView user selects company and it displays in DetailsView. In DetailsView I have custom button with "work" title. In database I have Table with default value of "300 dollar". And when user click on custom button "work" in DetailsView I want change the value in the database, something like 300+400 dollar = 700. dollar. So the new updated value needs to be 700. I tried to perform it and can't find solution.

I have .aspx page with "salary" label and custom button.

asp:DetailsView ID="DetailsView1" runat="server".....

<ItemTemplate>
    <asp:Label ID="Label5" runat="server" Text="Salary($):" Font-Size="Small" ForeColor="#9F9B9B"></asp:Label>
    <asp:Label ID="lblSalary" runat="server" Text='<%# Bind("Salary") %>'></asp:Label>
</ItemTemplate>

<asp:TemplateField ShowHeader="False">
    <ItemTemplate>
        <asp:Button ID="BtnWork" runat="server" CausesValidation="false" CommandName="" 
                        Text="Work" OnClick="BtnWork_Click" />
    </ItemTemplate>
</asp:TemplateField>

And aspx.cs page:

protected void BtnWork_Click(object sender, EventArgs e)
{
    MembershipUser currentUser = Membership.GetUser();
    Guid currentUserId = (Guid)currentUser.ProviderUserKey;

    string ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
    string sql = "SELECT * FROM Custon_MoneyWork WHERE UserId=@UserId";
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

平生欢 2024-12-06 15:16:55

听起来您不需要/不希望DetailsView 进行更新,因为该值不是来自用户,并且您使用的是自定义按钮而不是DetailsView 上的更新。如果是这种情况,您可以简单地使用 SqlCommand< /a> 并在您在帖子中删除的按钮单击事件处理程序中执行更新。

如果这不是您的目标,请告诉我,我会尽力建议另一种选择。

It sounds like you don't need/want the DetailsView to do the update since the value is not coming from the user and you are using a custom button and not an update on the DetailsView. If that is the case, you can simple use a SqlCommand and execute the update in the button click event handler that you stubbed out in your post.

If this was not your goal, let me know, and I'll do my best to suggest another option.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文