开发者

Custom button in DetailsView updates value in Database

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" Com开发者_如何学运维mandName="" 
                        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";
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜