Hi all,
am stuck up with c# code using value sort out in ascending order.
my problem is i cannot list out the values in ascending order. if the value is string.
but i can list out the values in ascending order. if the value is integer.
my question is, is there any way to bring up string value to ascending order?
my code is:
database:
price varchar(50)
status varchar(50)
c# code:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class ascending : System.Web.UI.Page
{
string str=ConfigurationManager.AppSettings["const"].ToString();
SqlConnection con = new SqlConnection();
protected void Page_Load(object sender, EventArgs e)
{
filladapriceband();
}
private object filladapriceband()
{
con = new SqlConnection(str);
ddpriceband.Items.Clear();
SqlDataReader dr = default(SqlDataReader);
SqlCommand sqlcmd = default(SqlCommand);
int count1 = 0;
count1 = 0;
try
{
sqlcmd = new SqlCommand("select distinct(price) from priceband where status=0 order by price asc", con);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
//dr = sqlcmd.ExecuteReader;
dr = sqlcmd.ExecuteReader();
while ((dr.Read()))
{
//ddpriceband.Items.Add(dr(0));
ddpriceband.Items.Add(dr[0].ToString());
count1 = count1 + 1;
}
ddpriceband.Items.Add("All");
Session.Add("selpb", "All");
return 0;
}
catch (Exception ex)
{
lblStatus.Text = "Unable to dispaly the avaliable pricebands.";
}
finally
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
}
return 0;
}
}
please drop a solution for this, its very much thankful to you.