I have one stubborn data grid view is refusing to display the bound data. i placed a grid view named exhibitgridview and set its datasource to none. then i added a standalone data source that can return columns into the grid but first there data displayed in the grid would be based on a what gets selected from a dropdown list. check it out from the picture below.
So basically some item is selected from the dropdown list next to the caseid label and the grid displays values accordingly... AS such i needed a selectedIndexchanged method so i had this in my page.cs
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
CreateDataSet();
caseID = DropDownList1.SelectedItem.Value.Trim();
DataV开发者_高级运维iew exhibitDataView = new DataView(exhibitDataSet.Tables[0]);
exhibitDataView.RowFilter = "FilingID = '" + caseID + "' ";
ExhibitGridView.DataSource = exhibitDataView;
ExhibitGridView.DataBind();
}
private void CreateDataSet()
{
exhibitConnection.ConnectionString =
ExhibitListSqlDataSource.ConnectionString;
exhibitSqlDataAdapter.SelectCommand = new
SqlCommand(ExhibitListSqlDataSource.SelectCommand, exhibitConnection);
exhibitSqlDataAdapter.Fill(exhibitDataSet);
}
The code runs sweet...I inserted a breakpoint as to ensure some data is actually returned for binding and there is...you can see that from the screen shot below:
that was until (ExhibitGridView.DataBind()). So when i run the next block, i expect the data to bind and display in the browser but for some unknown reason the gridview is acting stubborn. i tried specifying the datasource directly and it displays successfully at pageload but otherwise it wouldn't respond.
What could be the cause?
I do believe you need to supply your DataAdapter with the parameters that you are supplying your select statement with. Take a look.
I have given you an example from my code which uses OleDB (I have removed all the open / close connection for ease of reading). They are VERY similar.
SqlCmd = "select * from App_Details WHERE App_Name LIKE @Var";
aCommand = new OleDbCommand(SqlCmd, aConnection);
aCommand.Parameters.AddWithValue("@Var", value);
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(SqlCmd, aConnection);
OleDbCommandBuilder cmdBuilder = new OleDbCommandBuilder(dataAdapter);
// Now I do not see this part in your code right before you bind your data
dataAdapter.SelectCommand.Parameters.AddWithValue("@Var", value);
DataTable table = new DataTable();
dataAdapter.Fill(table);
dgvSearchApp.DataSource = table;
Make sure about Post Back events. Maybe the page is doing two post backs.
精彩评论