J
jgeisler
I'm having an issue with a sort that I'm doing on a DataView to
populate a dropdown.
In my database, I have all client last names encrypted, so when I
create a dataset sorted by "LastName," the DataSet returns the records
in the order of the encrypted last names, not the actual last name.
I then put the DataSet into a DataView, and then sort the DataView,
and it *sort* of works.
The problem that I have is that the most recent record that I enter
ends up at the end of the list, no matter what the first letter is.
For example, if I add "Adams" to the database as the latest record, it
will end up as the last item in the dropdown. If I then add "Brown" to
the database, "Brown" will end up as the last item in the dropdown,
and "Adams" will go to the correct position in the sort.
I've confirmed that this happens on the Dataview sort, not when adding
it to the dropdown.
Below is the commented code:
//populate dataset existingClients
getExistingClients();
//creating datatable to populate dataview from dataset
DataSet ds = new DataSet();
DataTable dt = new DataTable("Temp");
dt.Columns.Add("ID");
dt.Columns.Add("LastName");
dt.Columns.Add("FirstName");
ds.Tables.Add(dt);
DataView dv = ds.Tables["Temp"].DefaultView;
//populate dataview
foreach (DataRow row in existingClients.Tables["Client"].Rows)
{
DataRowView drv = dv.AddNew();
// change values in the DataRow.
drv["ID"] = row["ID"].ToString();
drv["LastName"] = Decrypt(row["LastName"].ToString());
drv["FirstName"] =
row["FirstName"].ToString();
}
//sort dataview
dv.Sort = "LastName,FirstName ASC";
//add to dropdown
foreach (DataRowView row in dv)
{
ListItem item = new ListItem();
item.Text = row["LastName"].ToString() + "," +
row["FirstName"].ToString();
item.Value = row["ID"].ToString();
cboExistingClient.Items.Add(item);
}
Thank you for any help you can give.
populate a dropdown.
In my database, I have all client last names encrypted, so when I
create a dataset sorted by "LastName," the DataSet returns the records
in the order of the encrypted last names, not the actual last name.
I then put the DataSet into a DataView, and then sort the DataView,
and it *sort* of works.
The problem that I have is that the most recent record that I enter
ends up at the end of the list, no matter what the first letter is.
For example, if I add "Adams" to the database as the latest record, it
will end up as the last item in the dropdown. If I then add "Brown" to
the database, "Brown" will end up as the last item in the dropdown,
and "Adams" will go to the correct position in the sort.
I've confirmed that this happens on the Dataview sort, not when adding
it to the dropdown.
Below is the commented code:
//populate dataset existingClients
getExistingClients();
//creating datatable to populate dataview from dataset
DataSet ds = new DataSet();
DataTable dt = new DataTable("Temp");
dt.Columns.Add("ID");
dt.Columns.Add("LastName");
dt.Columns.Add("FirstName");
ds.Tables.Add(dt);
DataView dv = ds.Tables["Temp"].DefaultView;
//populate dataview
foreach (DataRow row in existingClients.Tables["Client"].Rows)
{
DataRowView drv = dv.AddNew();
// change values in the DataRow.
drv["ID"] = row["ID"].ToString();
drv["LastName"] = Decrypt(row["LastName"].ToString());
drv["FirstName"] =
row["FirstName"].ToString();
}
//sort dataview
dv.Sort = "LastName,FirstName ASC";
//add to dropdown
foreach (DataRowView row in dv)
{
ListItem item = new ListItem();
item.Text = row["LastName"].ToString() + "," +
row["FirstName"].ToString();
item.Value = row["ID"].ToString();
cboExistingClient.Items.Add(item);
}
Thank you for any help you can give.