views:

76

answers:

1

Hi, 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["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.

+1  A: 

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....
}
o.k.w
Thank you. You just made my day! :)
Gabe Martin
You are welcome :P
o.k.w