0

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.

2
  • Where exactly do you want to change the value? The code you provided is the for datasource. You can definitely change that value on postback and do a rebind of whatever data control it is binded to. I'm not posting this as an answer because I'm not really sure of what you want to achieve. Commented Nov 22, 2009 at 2:09
  • I have a SqlDataSource with ControlParameter that has a property "DefaultValue". I would like to change whatever the value of the DefaultValue is to another value (e.g. 74) with a button control. Commented Nov 22, 2009 at 2:22

1 Answer 1

1

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....
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.