Click here to Skip to main content
15,894,180 members
Home / Discussions / Database
   

Database

 
GeneralRe: MySQL problem with varchar primary key Pin
razialx20-May-05 10:44
razialx20-May-05 10:44 
Generaltransaction, asp.net and access db Pin
fuel2run16-May-05 3:55
fuel2run16-May-05 3:55 
GeneralListBox event in a DataGrid's Header Pin
Nizar Abdeljaoued16-May-05 1:15
Nizar Abdeljaoued16-May-05 1:15 
GeneralRe: TextBox event in a DataGrid's Header Pin
Colin Angus Mackay16-May-05 1:36
Colin Angus Mackay16-May-05 1:36 
GeneralRe: ListBox event in a DataGrid's Header Pin
Nizar Abdeljaoued16-May-05 1:58
Nizar Abdeljaoued16-May-05 1:58 
GeneralQuestion concerning Sorting DataGrids Pin
nad226315-May-05 5:06
nad226315-May-05 5:06 
GeneralRe: Question concerning Sorting DataGrids Pin
Dominic Farr28-Jun-05 20:03
Dominic Farr28-Jun-05 20:03 
GeneralRe: Question concerning Sorting DataGrids Pin
Dominic Farr30-Jun-05 6:51
Dominic Farr30-Jun-05 6:51 
Two part to this.

Part1 (Save Row ID)
Each time a user selects a row in your DataGrid you need to save the row's unique idenifier.

Part2 (Re select Row based on ID)
After sorting, locate the new location of your selected row using the saved unique row identifier.

Example Part 1
// set selected row's id in view state
IEnumerator enu = ((DataView)DataGrid1.DataSource).GetEnumerator();
int index = 0;
while( index <= DataGrid1.SelectedIndex )
{
    enu.MoveNext();
    index++;
}

DataRowView rowView = enu.Current as DataRowView;
DataRow row = rowView.Row;
ViewState["item"] = (int)row["ID"];


Example Part 2
DataView sortView = dataSet1.MyTable.DefaultView;

// numberDiv is a static int
if( ( numberDiv % 2 ) == 0 )
{
	sortView.Sort = e.SortExpression + " ASC";
}
else
{
	sortView.Sort = e.SortExpression + " DESC";
}
numberDiv++;

// set new sort into ViewState
ViewState["sort"] = sortView.Sort;

// set sorted dataview
DataGrid1.DataSource = sortView;

// bind data
DataGrid1.DataBind();

// here reselected your row
// check that you have an item selected
if( ViewState["item"] != null )
{
    int id = (int)ViewState["item"];
    int index = -1;
    IEnumerator enu = sortView.GetEnumerator();
    while(enu.MoveNext())
    {	
        index++;	
        DataRowView rowView = enu.Current as DataRowView;	
        DataRow row = rowView.Row;	
        int rowID = (int)row["ID"];	
        if(rowID == id)
        {
            break; 
        }
    }
    DataGrid1.SelectedIndex = index;
}


Hope this helps.

My thanks to minhpc_bk
Questionupdateable query? Pin
Jerry Hammond15-May-05 4:56
Jerry Hammond15-May-05 4:56 
AnswerRe: updateable query? Pin
anj198315-May-05 5:20
anj198315-May-05 5:20 
GeneralTimeSpan instead of DateTime in a DataSet populated from a SQL Anywhere DB Pin
JasonJB14-May-05 4:38
JasonJB14-May-05 4:38 
GeneralGenerate Auto Number in SQL server 2000 Pin
imshally8114-May-05 0:42
imshally8114-May-05 0:42 
GeneralRe: Generate Auto Number in SQL server 2000 Pin
Colin Angus Mackay14-May-05 3:55
Colin Angus Mackay14-May-05 3:55 
GeneralLogin page Pin
Desi Bravo13-May-05 12:38
Desi Bravo13-May-05 12:38 
GeneralRe: Login page Pin
MoustafaS13-May-05 14:34
MoustafaS13-May-05 14:34 
GeneralRe: Login page Pin
Desi Bravo14-May-05 19:55
Desi Bravo14-May-05 19:55 
GeneralRe: Login page Pin
MoustafaS15-May-05 0:32
MoustafaS15-May-05 0:32 
GeneralRe: Login page Pin
Desi Bravo16-May-05 15:35
Desi Bravo16-May-05 15:35 
GeneralRe: Login page Pin
jonathan1516-May-05 1:59
jonathan1516-May-05 1:59 
GeneralRe: Login page Pin
Colin Angus Mackay16-May-05 6:08
Colin Angus Mackay16-May-05 6:08 
GeneralRe: Login page Pin
Desi Bravo16-May-05 15:34
Desi Bravo16-May-05 15:34 
GeneralRe: Login page Pin
Colin Angus Mackay16-May-05 22:04
Colin Angus Mackay16-May-05 22:04 
GeneralSqlDataReader Pin
Member 195262813-May-05 6:35
Member 195262813-May-05 6:35 
GeneralRe: SqlDataReader Pin
Colin Angus Mackay13-May-05 6:56
Colin Angus Mackay13-May-05 6:56 
GeneralRe: SqlDataReader Pin
Member 195262813-May-05 7:12
Member 195262813-May-05 7:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.