<script language="C#" runat="server"> string gstrSortOrder; // to hold the sort order string gstrFindText; // to hold the filter expression void Page_Load(Object sender, EventArgs e) { if (Page.IsPostBack) { // set the value to be used for the RowFilter on the DataView gstrFindText = "Title LIKE '*" + txtFindText.Text + "*'"; } else { // set the default values for the sort string and filter text box gstrSortOrder = "ISBN"; txtFindText.Text = "ASP"; } // recreate the data set and bind to the DataGrid control BindDataGrid(); } void SortRows(Object objSender, DataGridSortCommandEventArgs objArgs ) { // runs when the column headings in the DataGrid are clicked // get the sort expression (name of the column heading that was clicked) gstrSortOrder = objArgs.SortExpression.ToString(); // recreate the data set and bind to the DataGrid control BindDataGrid(); } void BindDataGrid() { // get connection string from ..\global\connect-strings.ascx user control string strConnect = ctlConnectStrings.OLEDBConnectionString; // create a SQL statement to select some rows from the database string strSelect = "SELECT * FROM BookList"; // create a variable to hold an instance of a DataView object DataView objDataView; // get DataView from get-dataview-control.ascx user control objDataView = ctlDataView.GetDataView(strConnect, strSelect); if (objDataView == null) return; // sort the rows in the DataView into the specified order objDataView.Sort = gstrSortOrder; // select the rows in the DataView that match the filter objDataView.RowFilter = gstrFindText; // set the DataSource property of the DataList MyDataGrid.DataSource = objDataView; // and bind the control to the data MyDataGrid.DataBind(); }</script>
<script language="C#" runat="server"> string gstrSortOrder; // to hold the sort order
string gstrFindText; // to hold the filter expression void Page_Load(Object sender, EventArgs e)
{
if (Page.IsPostBack)
{
// set the value to be used for the RowFilter on the DataView
gstrFindText = "Title LIKE '*" + txtFindText.Text + "*'";
}
else
{
// set the default values for the sort string and filter text box
gstrSortOrder = "ISBN";
txtFindText.Text = "ASP";
} // recreate the data set and bind to the DataGrid control
BindDataGrid();
}
void SortRows(Object objSender, DataGridSortCommandEventArgs objArgs )
{
// runs when the column headings in the DataGrid are clicked // get the sort expression (name of the column heading that was clicked)
gstrSortOrder = objArgs.SortExpression.ToString(); // recreate the data set and bind to the DataGrid control
BindDataGrid();
}
void BindDataGrid()
{
// get connection string from ..\global\connect-strings.ascx user control
string strConnect = ctlConnectStrings.OLEDBConnectionString; // create a SQL statement to select some rows from the database
string strSelect = "SELECT * FROM BookList"; // create a variable to hold an instance of a DataView object
DataView objDataView; // get DataView from get-dataview-control.ascx user control
objDataView = ctlDataView.GetDataView(strConnect, strSelect); if (objDataView == null)
return; // sort the rows in the DataView into the specified order
objDataView.Sort = gstrSortOrder; // select the rows in the DataView that match the filter
objDataView.RowFilter = gstrFindText; // set the DataSource property of the DataList
MyDataGrid.DataSource = objDataView; // and bind the control to the data
MyDataGrid.DataBind();
}</script>