DataGridView中扮演固执。它只是绑定难道不 [英] DataGridView playing stubborn. It just wouldnt bind

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

问题描述

我有一个固执的数据网格视图拒绝来显示数据绑定。
我把一个名为exhibitgridview网格视图,并设置其数据源无法比拟的。然后我说,可以返回列入电网,但在网格中显示第一有数据将基于一个什么获取从下拉列表中选择一个独立的数据源。检查它从下面的图片。

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

在code运行甜蜜......我插入一个断点,以确保某些数据实际上绑定返回,并且有...你可以看到,从下面的屏幕截图:

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 wouldnt respond...

这可能是什么原因?

推荐答案

我不相信你需要与您与您的供应select语句的参数提供您的DataAdapter。一起来看看。

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

我给你从我的code,它使用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天全站免登陆