Hiii,
I have a datagrid, to which I haved assigned values from database. Now using up/down buttons from column header i am trying to sort grid, but it is not doing sorting properly....
Example: i have column named LoanId. there are id's like 1,2...10,11...20...
now if i click on column Header Loan Id den it gives me result as 1,10,2,20,.....
i want result as 1,2,...10,11,....
can anyone help me?
thx n Regards
Amruta
Loading
VulpesPosted Sep 3, 2011, 3:44 PM
Amruta KirdatPosted Sep 3, 2011, 12:56 AM
@vulpes : at from load i have assigned ValueType property as u mentioned...but still it's not working...
steps wht i hve done till now
1. Datagridview columns property has different columns such as LoanId,CustomerName....
2. Fetched data in dataset and assiged to columns
3. at load i set valuetype property of column 0 to int
Code
at btnSearch:
grdCustLoanDetail.Rows[i].Cells[0].Value = dsSearch.Tables[0].Rows[i]["LoanId"].ToString();
at Load
grdCustLoanDetails.Columns[0].ValueType = typeof(int);
still prob is same
thx
Amruta KirdatPosted Sep 3, 2011, 12:44 AM
it's a windows application....
thx
Sam HobbsPosted Sep 2, 2011, 2:05 PM
So what is it? Is the applicaiton a Windows Forms application using a DataGridView or an ASP .Net applicaiton using a DataGrid or is it something else?
Satyapriya NayakPosted Sep 2, 2011, 9:40 AM
Note: Please Don't copy the controls from other app and paste it in current apps.Rather drag and drop it from the toolbox.
Try this -
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select * from student";
com = new OleDbCommand(str, con);
oledbda = new OleDbDataAdapter(com);
ds = new DataSet();
oledbda.Fill(ds, "student");
DataView dv = new DataView(ds.Tables["student"]);
dv.Sort = "sid desc";
dataGrid1.DataSource = dv;
con.Close();
Thanks
VulpesPosted Sep 2, 2011, 9:31 AM
Amruta KirdatPosted Sep 2, 2011, 8:59 AM
Loan Id is not a string column,it is number column...
thx
VulpesPosted Sep 2, 2011, 8:51 AM
To sort it the way you want, it needs to be an int column.
Alternatively, you could change the format of the strings to "01", "02" etc.