开发者

Change C# code with multiple button controls

I would like to know if it is possible to change the code "DefaultValue" in the C# file that is used by "example.aspx" by using a few button controls.

SqlDataSource1.SelectParameters开发者_Python百科["id"].DefaultValue = "value";

As you can see I already have part of what I need. I would just like to be able to insert different numbers (e.g. 14) into where it says "value" according to different buttons. If you dont understand what I am trying to say please refer to: Change the property “DefaultValue” of the asp.net “ControlParameter” control with javascript.


ASPX File:

<asp:Button ID="Button1" runat="server" Text="Value1" onclick="Button_Click" 
            CommandArgument="value1" />

<asp:Button ID="Button2" runat="server" Text="Value2" onclick="Button_Click" 
            CommandArgument="value2" />

CodeBehind (C#):

protected void Button_Click(object sender, EventArgs e)
{
    Button button = sender as Button;
    SqlDataSource1.SelectParameters["id"].DefaultValue = button.CommandArgument;

    // Your other codes for e.g. databinding....
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜