Groups > Asp .Net > Getting started with ASP.NET > Re: Sort a datalist by clicking on radio button




Sort a datalist by clicking on radio button

Sort a datalist by clicking on radio button
Thu, 3 Apr 2008 22:48:31 +0000
Hi i ahve a datalist, above it i have two radio buttons, one which is price and
the other quantity. I want my results to be sorted based on which one has been
clicked,  here is what i have done so far but i am having trouble on how to
proceed. Here is my code;protectedvoid Page_Load(object sender, EventArgs e)

{if (!IsPostBack)

{String str = Session["subCategoryID"].ToString();

SqlConnection conn =
newSqlConnection(ConfigurationManager.ConnectionStrings["streamConnectionSt
ring"].ConnectionString);SqlCommand command =
newSqlCommand("stream_CategoryResults", conn);

command.Parameters.Add("@subCategoryID", SqlDbType.Int).Value =
str;command.CommandType = CommandType.StoredProcedure;

conn.Open();SqlDataAdapter Results = newSqlDataAdapter(command);

DataSet ds = newDataSet();Results.Fill(ds, "ResultsTable");

conn.Close();dgProducts.DataSource =
ds.Tables["ResultsTable"].DefaultView;ds.Tables["ResultsTable&quo
t;].DefaultView.Sort = "productPrice Asc";

dgProducts.DataBind();

 

}

}protectedvoid RadioButton1_CheckedChanged(object sender, EventArgs e)

{

}

What needs to go in the radio button checked changed area, thank you
Post Reply
Re: Sort a datalist by clicking on radio button
Thu, 3 Apr 2008 22:53:36 +0000
check 

if(rbl.SelectedItem.Text == "price")

then  pass your sort statement here.

else if(rbl.SelectedItem.Text == "quantity")

your sort statement. 

 if(rbl.SelectedItem.Text == "price")
Post Reply
Re: Sort a datalist by clicking on radio button
Thu, 3 Apr 2008 22:55:12 +0000
Hi would i place that in this method;protectedvoid
RadioButton1_CheckedChanged(object sender, EventArgs e)

{

}
Post Reply
Re: Sort a datalist by clicking on radio button
Thu, 3 Apr 2008 23:00:37 +0000
Also would i need to create a stored procedure for each sort criteria, since i
am using stored procedures.
Post Reply
Re: Sort a datalist by clicking on radio button
Thu, 3 Apr 2008 23:17:15 +0000
hi, no, you don't have to, you can do something like this if your SP retruning
price and quantity in the table


RadioButtonList1.SelectedValue --> the value can be product or quantity


dgProducts.DataSource =
ds.Tables["ResultsTable"].DefaultView;ds.Tables["ResultsTable&quo
t;].DefaultView.Sort = RadioButtonList1.SelectedValue + " ASC";

dgProducts.DataBind();
Post Reply
<< Previous 1 2 Next >>
( Page 1 of 2 )
about | contact