DataGridView玩固执。它只是不会绑定 [英] DataGridView playing stubborn. It just wouldn't bind

查看:91
本文介绍了DataGridView玩固执。它只是不会绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个顽固的数据网格视图,它拒绝显示绑定的数据。
我放置了一个名为Exhibitiongridview的网格视图,并将其数据源设置为none。然后我添加了一个独立的数据源,该数据源可以将列返回到网格中,但是首先,网格中显示的数据将基于从下拉列表中选择的数据。从下面的图片中查看。

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.

因此,基本上从中选择了某些项目在caseid标签旁边的下拉列表中,网格会相应地显示值...例如,我需要一个selectedIndexchanged方法,因此我在page.cs

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();

        DataView 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:

直到(ExhibitGridView.DataBind())。因此,当我运行下一个块时,我希望数据绑定并显示在浏览器中,但是由于某些未知原因,Gridview表现得很固执。我尝试直接指定数据源,它会在页面加载时成功显示,但否则不会响应。

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.

可能是什么原因?

推荐答案

我确实认为您需要为DataAdapter提供与select语句一起提供的参数。看看。

I do believe you need to supply your DataAdapter with the parameters that you are supplying your select statement with. Take a look.

我已经从我的代码中为您提供了一个使用OleDB的示例(为了方便阅读,我删除了所有打开/关闭连接)。它们非常相似。

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;

这篇关于DataGridView玩固执。它只是不会绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆