Structuring button click methods to avoid code repetition
<p>I have the following two button click methods that create an array from three TextBoxes, order the values, insert them into a database and then select the values in the same order. The only difference between the two buttons is that one orders the values in ascending order and the other in descending order.</p>

<p>I'm not used to working with C#. Can anybody suggest the best way to structure my code so I'm not repeating it for each button? Normally I'd write a function and have each button pass it arguments. Is that the right way to go here?</p>

<p>Thanks in advance.</p>

<p><strong>Button1</strong></p>

<pre><code>protected void Button1_Click(object sender, EventArgs e)
{
    var list = new string[] { TextBox1.Text, TextBox2.Text, TextBox3.Text };
    var orderedlist = list.OrderBy(x =&gt; (x)).ToArray();
</code></pre>

<p>...</p>

<pre><code>    SqlCommand cmd = new SqlCommand("Select * from lists order by values asc", conn);
</code></pre>

<p><strong>Button2</strong></p>

<pre><code>protected void Button2_Click(object sender, EventArgs e)
{
    var list = new string[] { TextBox1.Text, TextBox2.Text, TextBox3.Text };
    var orderedlist = list.OrderByDescending(x =&gt; (x)).ToArray();
</code></pre>

<p>...</p>

<pre><code>    SqlCommand cmd = new SqlCommand("Select * from lists order by values desc", conn);
</code></pre>
